如何使用线程/线程池管理多个操作



我需要创建一个并行执行多个操作的应用程序。我曾考虑过使用线程或线程池,但我以前从未使用过,所以我觉得这很困难。线程应该以以下方式工作:

MainSystem -> get average of the 3 systems below
----System 1 -> perform increment/decrement
----System 2 -> get average of the 3 subsystems below
--------3 subsystems -> each system perform increment/decrementindependently
----System 3 -> get average of the 15 subsystems below
--------15 subsystems -> each system perform increment/decrement independently

所有系统应同时运行。你认为我应该如何实现这一点?

你试过什么?你可以利用并行:

Parallel.ForEach(calculations, (currentCalc) => 
{
    // perform calculation
});   

请参阅https://msdn.microsoft.com/en-CA/library/dd460720(v=vs.110).aspx

请提供您需要执行的实际计算的更多详细信息。

最新更新