基本上,我希望一次处理多个线程中的项目列表,而不是一次处理一个项目。 我只想要一次有限数量的线程。 这种方法有意义吗?线程数是唯一选项使用全局变量吗? (下面的伪代码)使用多个有限数量的线程处理项目列表
foreach item in list
while thread_count >= thread_max
sleep
loop
start_thread item
thread_count++
next
function start_thread(item)
do_something_to item
thread_count--
end function
这个机制来与OSTB .NET 4.0。 :) – bzlm 2011-03-02 22:07:08
你为什么要控制线程的数量?通过使用[Threadpool](http://msdn.microsoft.com/en-us/library/system.threading.threadpool(v = VS.100).aspx)让框架最优地决定。 – 2011-03-04 08:18:05
因此,我可以运行列表并在每个项目上使用QueueUserWorkItem,而不用担心有多少个线程正在运行?游泳池会为我管理吗?有趣... – 2011-03-04 18:56:30