如何使用 threads/thread 池管理多个操作?
How to manage multiple operations using threads/thread pool?
我需要创建一个可以并行执行多个操作的应用程序。我在考虑使用线程或线程池,但我以前从未使用过它,所以我觉得这很困难。
线程应按以下方式工作:
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
请提供更多关于您需要执行的实际计算的详细信息。
我需要创建一个可以并行执行多个操作的应用程序。我在考虑使用线程或线程池,但我以前从未使用过它,所以我觉得这很困难。 线程应按以下方式工作:
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
请提供更多关于您需要执行的实际计算的详细信息。