Asynchronous programming with async and await
When to use Asynchronous?
Accessing the Web, Working with files or DB, working with images
synchronous vs. asynchronous
Asynchronous programming improves responsiveness, synchronous blocks the flow
Return Type
Task Object: A Task is an object that encapsulates the state of an asynchronous operation.
What is Await?
This is just a marker for the compiler. So when the compiler sees that, it knows that this operation is going to be costly, and it may take a bit of time. In that case, instead of blocking this thread, it's going to return the control immediately to the color of this method here.
Method name suffix
You should add Async suffix to your method names public async Task DownloadHtmlAsync
What version was Async/Await introduced?
dotnet framework 4.5
Use Case
if you're building WPF applications or applications for the Windows Runtime, wherever you have blocking operations like accessing files, accessing database, calling Web services or accessing Web as you see here, accessing the calendar, address book, on a Windows mobile, all of these are blocking operations and you can improve the responsiveness of your application by using async and await.
asynchronous process
the application can continue with other work that doesn't depend on the web resource until the potentially blocking task finishes
asynchronous program execution
when a function is called, program execution continues to the next line without waiting for that function to complete.