Introduction

Asynchronous or parallel or concurrent programming made simple!

You can easily follow this sample and try and adopt async programming style to deliver better user experiences in addition to help improve "real" performance.

This sample demonstrates how to write async code using Tasks, Async & Await in C#. This solutions makes use of a freshly created console application so that we can really focus on the asynchronous code.

This sample is a real good start point for developers or programmers who wish to get started on asynchronous or parallel programming in C#. This sample is purposely kept very simple so that even novice programmers can easily follow the code & try the concepts in their own applications!

 

To open a solution

  1. Extract all files.
     
  2. Start Microsoft Visual Studio 2013.
     
  3. On the File menu, click Open, and then click Project/Solution.
     
  4. Navigate to the folder containing the .sln file, select it, and then click Open.

To run the sample

  1. Double-click TaskAsyncAwaitSample.sln to open the solution.

  2. Press F5 to start debugging the app.

 

Code Highlights

C#
Edit|Remove
// make the non-blocking call 
Task<bool> result = DoWorkAsyc();
 
C#
Edit|Remove
// lets wait for the results to come 
result.Wait();
 
C#
Edit|Remove
// run the actual long running process as a Task 
return await Task.Run(() => ProcessJob());

Conclusion

Using async, tasks, await we can code parallel or asynchronous code and thus make the client code non-blocking, which results in a better end user experience!

 

for more information on Windows Azure / .NET development, please visit my blog!