Click here to Skip to main content
Click here to Skip to main content

C# 5.0 Async/Await Demo Code

By , 9 Oct 2012
 

I’ve published the sample code I use to demonstrate the use of async/await in C# 5.0. You can find it here.StatCounter

Projects

PauloMorgado.AyncDemo.WebServer

This project is a simple web server implemented as a console application using Microsoft ASP.NET Web API self hosting and serves an image (with a delay) that is accessed by the other projects.

This project has a dependency on Json.NET due to the fact the the Microsoft ASP.NET Web API hosting has a dependency on Json.NET.

The application must be run on a command prompt with administrative privileges or a urlacl must be added to allow the use of the following command:

netsh http add urlacl url=http://+:9090/ user=machine\username

To remove the urlacl, just use the following command:

netsh http delete urlacl url=http://+:9090/

PauloMorgado.AsyncDemo.WindowsForms

This Windows Forms project contains three regions that must be uncommented one at a time:

Sync with WebClient

This code retrieves the image through a synchronous call using the WebClient class.

Async with WebClient

This code retrieves the image through an asynchronous call using the WebClient class.

Async deadlock

This code how async operations can still deadlock.

Async with HttpClient with cancelation

This code retrieves the image through an asynchronous call with cancelation using the HttpClient class.

PauloMorgado.AsyncDemo.Wpf

This WPF project contains three regions that must be uncommented one at a time:

Sync with WebClient

This code retrieves the image through a synchronous call using the WebClient class.

Async with WebClient

This code retrieves the image through an asynchronous call using the WebClient class.

Async deadlock

This code how async operations can still deadlock.

Async with HttpClient with cancelation

This code retrieves the image through an asynchronous call with cancelation using the HttpClient class.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Paulo Morgado
Software Developer (Senior) Paulo Morgado
Portugal Portugal
Member

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 9 Oct 2012
Article Copyright 2012 by Paulo Morgado
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid