Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对于任务,continueWith和WhenAll()、何时继续、何时完成任务或何时完成ConitueWith?_C#_Asynchronous_Task Parallel Library - Fatal编程技术网

C# 对于任务,continueWith和WhenAll()、何时继续、何时完成任务或何时完成ConitueWith?

C# 对于任务,continueWith和WhenAll()、何时继续、何时完成任务或何时完成ConitueWith?,c#,asynchronous,task-parallel-library,C#,Asynchronous,Task Parallel Library,我有几个任务,每个任务都有一个使用任务结果的连续体。诸如此类: Task myTask01 = myMethod01Async().ContinueWith((a) => //do somenthing with a.result); Task myTask02 = myMethod02Async().ContinueWith((a) => //do somenthing with a.result); Task.WhenAll(myTask01, myTask02); 我知

我有几个任务,每个任务都有一个使用任务结果的
连续体。诸如此类:

Task myTask01 = myMethod01Async().ContinueWith((a) => //do somenthing with 
a.result);

Task myTask02 = myMethod02Async().ContinueWith((a) => //do somenthing with a.result);

Task.WhenAll(myTask01, myTask02);
我知道WhenAll会一直等到参数中的所有任务完成。但在这种情况下,我有一个
ContinueWith
,我不知道是等到所有
ContinueWith
都完成,还是在
Task01
Task02
完成时继续,所以代码继续,尽管
ContinueWith
代码仍在运行。

返回一个新任务,因此使用task。实际上,您正在等待从
ContinueWith
返回的任务,而不是从
myMethod01Async
myMethod02Async
返回的任务


所以是的,任务。WhenAll将等待
ContinueWith
中的代码完成。

“我不知道WhenAll是等待所有ContinueWith完成,还是在Task01和Task02完成时继续”——任务
Task01
Task02
正是
ContinueWith()完成时的表示。你的问题没有多大意义,因为你暗示他们是不同的,而事实上他们是一样的。当然,如果您刚刚阅读了文档,甚至尝试了一个示例,您就能够回答您自己的问题。那么我不明白为什么在我的示例中它不能像这样工作: