2015-12-10 77 views
1

我需要创建一个并行执行多个操作的应用程序。我正在考虑使用线程或线程池,但之前我从未使用过,所以我觉得这很困难。 螺纹应工作方式如下:如何使用线程/线程池管理多个操作?

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 

所有系统应在同一时间进行。你认为我应该如何实施?

回答

1

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

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

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

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

+0

这只是一个简单的递增/递减操作,我需要。我甚至不知道这件事,但我认为它会像魅力一样工作。谢谢! – user1012732

+0

我该如何避免死锁? – user1012732

+0

你在哪里陷入僵局?请显示一些代码。 – Roger