Skip to content

Instantly share code, notes, and snippets.

@agtokty
Last active April 17, 2019 10:44
Show Gist options
  • Save agtokty/5e379df302cc0d82b0c9bcbcc22e042f to your computer and use it in GitHub Desktop.
Save agtokty/5e379df302cc0d82b0c9bcbcc22e042f to your computer and use it in GitHub Desktop.
make async call sync and get result.
public static class Extensions
{
public static T MakeSync<T>(this Task<T> task)
{
task.Wait();
return task.Result;
}
}
example :
normal usage with await :
var client = new HttpClient();
var response = await client.GetAsync("http://google.com");
extension usage :
var client = new HttpClient();
var response = client.GetAsync("http://google.com").MakeSync();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment