Using C# HttpClient from Sync and Async code

Asynchronous programming is a modern of way of writing code and it enhances the overall page responsiveness and avoids the performance bottlenecks. The .NET 4.5 and C# 5 provides a neat and clean way of implementing http client using 
System.Net.Http.HttpClient()

Advantage of Asynchronous vs synchronous code

  1. In Synchronous process the entire application must wait until the request is executed.
  2. During the asynchronous process the application UI continues to respond and also enhances the page responsive.
  3. Async methods are easier to code. Async and await keywords in c# are the heart of async programming 

Example of HttpClient using Asynchronous programming with Async and Await

Now let’s see how to call these get method using synchronous and asynchronous way

Example of HttpClient PUT Request using Asynchronous code

Calling the above HttpClient PUT using Synchronous and Asynchronous way

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.