Use an async callback with Task.ContinueWith

后端 未结 3 1905
长情又很酷
长情又很酷 2020-12-01 08:45

I\'m trying to play a bit with C#\'s async/await/continuewith. My goal is to have to have 2 tasks which are running in parallel, though which task is executing a sequence of

3条回答
  •  死守一世寂寞
    2020-12-01 09:50

    When chaining multiple tasks using the ContinueWith method, your return type will be Task whereas T is the return type of the delegate/method passed to ContinueWith.

    As the return type of an async delegate is a Task, you will end up with a Task and end up waiting for the async delegate to return you the Task which is done after the first await.

    In order to correct this behaviour, you need to use the returned Task, embedded in your Task. Use the Unwrap extension method to extract it.

提交回复
热议问题