Skip to content

Instantly share code, notes, and snippets.

@rolfbjarne
Forked from anujb/gist:4727142
Created February 7, 2013 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolfbjarne/4734905 to your computer and use it in GitHub Desktop.
Save rolfbjarne/4734905 to your computer and use it in GitHub Desktop.
public class MyViewController : UIViewController {
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
for (int i = 0; i < Int32.MaxValue; i++) {
DoStuffAsync();
}
}
public void DoStuffAsync() {
Task.Factory.StartNew<string> (() => {
using (var client = new WebClient()) {
var response = client.DownloadString (new Uri ("http://www.google.com"));
return response;
}
}).ContinueWith ((t) => {
Console.WriteLine(t);
this.DoSomethingElse();
});;
}
public void DoStuffAsyncWeak() {
var weakViewController = new WeakReference (this);
Task.Factory.StartNew<string> (() => {
using (var client = new WebClient()) {
var response = client.DownloadString (new Uri ("http://www.google.com"));
return response;
}
}).ContinueWith ((t) => {
Console.WriteLine(t);
var strongViewController = weakViewController.Target as MyViewController;
if (strongViewController == null)
return;
strongViewController.DoSomethingElse();
});;
}
public void DoSomethingElse() {
Console.WriteLine ("I'm doing something else now...");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment