Create a completed Task

前端 未结 8 1896
名媛妹妹
名媛妹妹 2020-11-28 06:13

I want to create a completed Task (not Task). Is there something built into .NET to do this?

A related question: Create a complete

相关标签:
8条回答
  • 2020-11-28 07:05

    For .Net 4.6 and above use

    return Task.CompletedTask;
    

    For lower version you can use

    return new Task(() => { });
    
    0 讨论(0)
  • 2020-11-28 07:07

    You can use Nito.AsyncEx.TaskConstants.Completed from a great library AsyncEx from Stephen Cleary.

    0 讨论(0)
提交回复
热议问题