问题
In one of my applications, I have to use multiple threads.
As a better approach, I have replaced a thread queue by ThreadPool
.
At start of Form, I set Min/Max Threads as follows:
ThreadPool.SetMaxThreads(20,20)
ThreadPool.SetMinThreads(1,1)
Later on while using, I use ThreadPool
as follow:
Function()
{
ThreadPool.QueueUserWorkItem(new WaitCallback(Action), arguments);
}
I am not using any sort of DeQueue
.
It will be help full if some one can share their experience with ThreadPool
(specially Set MIN/MAX interfaces)
Regards, Sachin
回答1:
Generally, it's not recommended to change the thread pool size. From MSDN:
Use caution when changing the maximum number of threads in the thread pool. While your code might benefit, the changes might have an adverse effect on code libraries you use.
If the common language runtime is hosted, for example by Internet Information Services (IIS) or SQL Server, the host can limit or prevent changes to the thread pool size.
The CLR or the host (e.g. IIS) on its own will determine whether to increase or decrease the thread pool size based on the threading patterns of your application so if I were you, I wouldn't bother playing with these numbers.
Hope this helps.
来源:https://stackoverflow.com/questions/20699392/guidelines-while-using-threadpool-setmaxthreads-and-threadpool-setminthreads-in