Created
January 16, 2012 13:34
-
-
Save deanhume/1620903 to your computer and use it in GitHub Desktop.
Async Controller - IndexAsync()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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