ThreadPool.QueueUserWorkItem性能测试与提高

            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);
            }




你可能感兴趣的:(计算机)