Spawn Multiple Threads for work then wait until all finished

后端 未结 12 1569
遇见更好的自我
遇见更好的自我 2020-11-28 01:46

just want some advice on \"best practice\" regarding multi-threading tasks.

as an example, we have a C# application that upon startup reads data from various \"type

12条回答
  •  悲哀的现实
    2020-11-28 02:14

    If you are using .NET 3.5 or below, you can use an array of AsyncResult or BackgroundWorker and count how many threads have returned (just don't forget to decrease counter with interlocked operations) (see http://www.albahari.com/threading/ as a reference).

    If you are using .NET 4.0 a parallel for is the simplest approach.

提交回复
热议问题