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?
Comparing mono repository with dotnet repository I've found, that mono implementation of HttpClient do not call CancellationTokenSource.Cancel() in Dispose method and I believe that's the reason of inconsistency between platforms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With