Skip to content

Instantly share code, notes, and snippets.

@bikrone
Created July 9, 2015 11:41
Show Gist options
  • Save bikrone/4982694b1abaa5594bfe to your computer and use it in GitHub Desktop.
Save bikrone/4982694b1abaa5594bfe to your computer and use it in GitHub Desktop.
C# Tasks
public static Task<string> downloadUrl(string url)
{
return new Task<string>(() =>
{
Task<string> task;
using (WebClient wc = new WebClient())
{
Console.WriteLine("Start downloading");
task = wc.DownloadStringTaskAsync(url);
task.Wait();
}
return task.Result;
});
}
// using
var download = downloadUrl("http://manga24h.com");
download.Start();
download.ContinueWith((task) => {
Console.Write(task.Result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment