Create a completed Task

前端 未结 8 1928
名媛妹妹
名媛妹妹 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 06:51

    The newest version of .Net (v4.6) is adding just that, a built-in Task.CompletedTask:

    Task completedTask = Task.CompletedTask;
    

    That property is implemented as a no-lock singleton so you would almost always be using the same completed task.

提交回复
热议问题