Простые параллельные задачи с продолжением ⇐ C#
Простые параллельные задачи с продолжением
I have been reading for the 2 hours and I am still confused. Some say use StartNew, some say Task.Run some say something else. I do know that Task.Run is giving me a compile error.
I need to start multiple tasks in parallel and then when each completes successfully do a continuation task. Knowing when all are done with blocking would be helpful.
Here is what I have:
public void DoSomeWork(object workItem) { var tasks = new Task[_itemList.Count]; for (int loopCnt = 0; loopCnt < _itemList.Count; loopCnt++) { tasks[loopCnt] = new Task.Run(() => { return _itemList[loopCnt].Analyze(workItem); }); tasks[loopCnt].ContinueWith(ReportResults, TaskContinuationOptions.ExecuteSynchronously); } } The compile says Run does not exist in Task.
Obviously, I have something run but I do not know what.
How do I get past this problem?
Источник: https://stackoverflow.com/questions/424 ... ntinuation
I have been reading for the 2 hours and I am still confused. Some say use StartNew, some say Task.Run some say something else. I do know that Task.Run is giving me a compile error.
I need to start multiple tasks in parallel and then when each completes successfully do a continuation task. Knowing when all are done with blocking would be helpful.
Here is what I have:
public void DoSomeWork(object workItem) { var tasks = new Task[_itemList.Count]; for (int loopCnt = 0; loopCnt < _itemList.Count; loopCnt++) { tasks[loopCnt] = new Task.Run(() => { return _itemList[loopCnt].Analyze(workItem); }); tasks[loopCnt].ContinueWith(ReportResults, TaskContinuationOptions.ExecuteSynchronously); } } The compile says Run does not exist in Task.
Obviously, I have something run but I do not know what.
How do I get past this problem?
Источник: https://stackoverflow.com/questions/424 ... ntinuation
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение