Thread vs ThreadPool - .Net 2.0

谁都会走 提交于 2019-12-24 10:57:33

问题


I'm not able to understand the difference between Thread vs ThreadPool. Consider i've to manipulate 50,000 records using threads.

In case of threads i need to either predefine no of threads or no of records per threads. Either of them has to be constant.

In case of threadpool we dont need to set any of them theoretically. But practically we need to assign the number of records per thread, because the no of threads may grow extremely large if the input no of records is huge.

Any insights on this?


回答1:


There is a huge cost in creating and destroying threads. A thread pool takes away this problem by maintaining open threads for you. When a thread in a pool is done with its work, the thread is returned to the pool instead of being destroyed. Then when you have to do more work, the already open thread is taken from the pool. This is much more efficient.




回答2:


Here is a complete treatment on Threads and ThreadPools that will answer your question. includes when to use one vs the other.

http://www.yoda.arachsys.com/csharp/threads/



来源:https://stackoverflow.com/questions/2675477/thread-vs-threadpool-net-2-0

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