Create a completed Task

Timothy Shields picture Timothy Shields · Jan 9, 2013 · Viewed 84k times · Source

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

A related question: Create a completed Task<T>

Answer

i3arnon picture i3arnon · Oct 7, 2014

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.