I have a method like this:
private async Task DoSomething()
{
// long running work here.
}
When I call the method like this it blocks the UI:
Task t = DoSomething();
I have to do one of these to make it non-blocking:
Task t = new Task(() => DoSomething());
t.Start();
// Or
Task t = Task.Factory.StartNew(() => DoSomething());
So what is the point of async / await when you can just use Tasks as they were in framework 4 and use Task.Wait() in place of await?
EDIT:
I understand all of your answers – but none really address my last paragraph. Can anyone give me an example of Task based multi-threading where async / await improves the readability and/or flow of the program?
asyncmethods begin their execution synchronously.asyncis useful for composing asynchronous operations, but it does not magically make code run on another thread unless you tell it to.You can use
Task.Runto schedule CPU-bound work to a threadpool thread.See my
async/awaitintro post or theasyncFAQ for more information.