开发者

Difference between ThreadPool Items?

Are they same meaning?

And How should I use ThreadPool.SetMaxThreads(20, 20); because I can not see 20 thread working asynchronously?

ThreadPool.SetMaxThreads(20, 20);
    ThreadPool.QueueUserWorkItem(new WaitCallback(WorkThread), DateTime.Now);

and

for (int i = 0; i < 20; i++)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(WorkThread),开发者_如何学Go DateTime.Now);
        }


How many threads the pool uses is largely up to it, and may vary based on what else is going on, the number of unstarted items, etc; you are only setting the max. You aren't the only user of the pool; .net uses that itself, so don't mess with it. If you explicitly want 20 threads, create 20 Threads.


ThreadPool is implemented differently in .NET 4 (as opposed to .NET).

When you set Max ThreadPool, you are saying how many you want threadPool to create if required. If queued task is quick, it might be able to process it even with couple of them without creating 20 Threads.

You could set SetMinThreads, that will ensure that it creates minimum number of threads first. But be careful on this, as creating threads is resources hit

see MSDN article

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜