Convert Syncronous call to Asyncronous call Using C#


  • Convert Syncronous call to Asyncrounous call
    • Syncronous call
      • string html = WebClient().DownloadString( new Uri ("http://www.albahari.com/threading"));
    • Sync to Async Using Task Library
      • Task task = new WebClient().DownloadStringTaskAsync (new Uri ("http://www.albahari.com/threading"));
      • task.ContinueWith (_ =>
      • {
      • if (task.Exception != null)
      • task.Exception.InnerException.Dump();
      • else
      • {
      • string html = task.Result;
      • html.Dump();
      • }
      • });
    • Sync to Async Using Await feature
      • Task task = new WebClient().DownloadStringTaskAsync (new Uri ("http://www.albahari.com/threading"));
      • string html = await task;
      • html.Dump();


Comments

Popular posts from this blog

Authorize.net Integration eCommerce Payment Gateway ( Direct Post Method New! )

Get Organised with OneNote

Test your Sql Query Online