ThreadPool.QueueUserWorkItem性能测试与提高

来源:互联网 发布:好用的乳液推荐知乎 编辑:程序博客网 时间:2024/06/05 10:56
            int minWorker, minIOC;            // Get the current settings.            ThreadPool.GetMinThreads(out minWorker, out minIOC);            this.textBox1.AppendText(string.Format("min worker number {0}\r\n", minWorker));            ThreadPool.SetMinThreads(10, minIOC);            ThreadPool.GetMinThreads(out minWorker, out minIOC);            this.textBox1.AppendText(string.Format("set min worker number to {0}\r\n", minWorker));            for (int index = 0; index < 9; index++)            {                ThreadPool.QueueUserWorkItem((indexParam) =>                {                    int threadID = Thread.CurrentThread.ManagedThreadId;                    Thread.Sleep(1000);                    BeginInvoke((Action)delegate { this.textBox1.AppendText("Completed " + indexParam.ToString() + " using thread " + threadID.ToString() + "  (" + DateTime.Now.Second.ToString() + "." + DateTime.Now.Millisecond.ToString("000") + ")\r\n"); });                }, index);                Thread.Sleep(20);            }




0 0
原创粉丝点击