After reading Stephen Cleary blog post about eliding async and await I've decided to go and play around with it. I wrote very simple console app with HttpClient using Visual Studio For Mac .
public static async Task Main(string[] args)
{
Console.WriteLine(await Get());
Console.WriteLine("Hello World!");
}
public static Task<string> Get()
{
using (var http = new HttpClient())
return http.GetStringAsync("http://google.com");
}
According to blog post it should throw an exception but it didn't . If I switch to Windows and try to run this app, I will get TaskCancelledException as expected, but on macOS it works perfectly fine.
Proof that Google.com was printed into console without exception on macOS
As I believe the reason behind this behaviour is different implementation of IDisposable in HttpClient on both platforms, but... why?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.