Skip to content

Instantly share code, notes, and snippets.

@deanhume
Created January 16, 2012 13:34
Show Gist options
  • Save deanhume/1620903 to your computer and use it in GitHub Desktop.
Save deanhume/1620903 to your computer and use it in GitHub Desktop.
Async Controller - IndexAsync()
public void IndexAsync()
{
AsyncManager.OutstandingOperations.Increment(2);
Task.Factory.StartNew(() =>
{
// Perform some expensive operation
string uri = "http://www.deanhume.com";
WebClient client = new WebClient();
string reply = client.DownloadString(uri);
AsyncManager.Parameters["data"] = reply;
AsyncManager.OutstandingOperations.Decrement();
});
Task.Factory.StartNew(() =>
{
// Perform another expensive operation
string uri = "http://www.deanhume.com/home/about";
WebClient client = new WebClient();
string reply = client.DownloadString(uri);
AsyncManager.Parameters["moredata"] = reply;
AsyncManager.OutstandingOperations.Decrement();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment