Created
July 9, 2015 11:41
-
-
Save bikrone/4982694b1abaa5594bfe to your computer and use it in GitHub Desktop.
C# Tasks
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 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