Guidelines while using: ThreadPool.SetMaxThreads and ThreadPool.SetMinThreads in C#

此生再无相见时 提交于 2021-01-28 21:07:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!