Parallel.Foreach spawning way too many threads

前端 未结 4 554
野的像风
野的像风 2020-12-15 08:41

The problem

Although the code about which I will talk here I wrote in F#, it is based on the .NET 4 framework, not specifically depending on any particularity of F

4条回答
  •  独厮守ぢ
    2020-12-15 09:15

    You could always use a ThreadPool.

    http://msdn.microsoft.com/en-us/library/system.threading.threadpool.aspx

    basically:

    1. Create a thread pool
    2. Set the max number of threads
    3. Queue all the tasks using QueueUserWorkItem(WaitCallback)

提交回复
热议问题