Cancellation Token in await method

前端 未结 1 1524
有刺的猬
有刺的猬 2021-01-13 01:29

There are many reasons to put a token in the constructor of a task, mentioned here: Cancellation token in Task constructor: why?

With the use of keywords, async / aw

相关标签:
1条回答
  • 2021-01-13 02:07

    You aren't supposed to use the Task constructor in async methods. Usually, you just want to pass the CancellationToken on, like this:

    public async Task MethodAsync(CancellationToken token)
    {
      await Method01Async(token);
      await Method02Async(token);
    }
    
    0 讨论(0)
提交回复
热议问题