Last active
April 17, 2019 10:44
-
-
Save agtokty/5e379df302cc0d82b0c9bcbcc22e042f to your computer and use it in GitHub Desktop.
make async call sync and get result.
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 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