Created
September 16, 2011 22:11
C# async and await example
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Net; | |
using System.Threading.Tasks; | |
namespace AsyncCSharp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Starting..."); | |
var smsohanDotCom = GetSmSohanDotCom(); | |
Console.WriteLine("Passed the get line, status {0}", smsohanDotCom.IsCompleted); | |
Console.WriteLine(smsohanDotCom.Result.Length); | |
Console.WriteLine("Printed the length, status {0}", smsohanDotCom.IsCompleted); | |
Console.ReadLine(); | |
} | |
private async static Task<String> GetSmSohanDotCom(){ | |
Console.WriteLine("Before Waiting..."); | |
var data = await new WebClient().DownloadStringTaskAsync(new Uri("http://smsohan.com")); | |
Console.WriteLine("Waiting..."); | |
return data; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment