diff --git a/src/ModernHttpClient/Android/OkHttpNetworkHandler.cs b/src/ModernHttpClient/Android/OkHttpNetworkHandler.cs index 8a4fd62..7a48c69 100644 --- a/src/ModernHttpClient/Android/OkHttpNetworkHandler.cs +++ b/src/ModernHttpClient/Android/OkHttpNetworkHandler.cs @@ -11,6 +11,7 @@ using Java.IO; using System.Security.Cryptography.X509Certificates; using System.Globalization; +using Android.OS; namespace ModernHttpClient { @@ -85,7 +86,9 @@ protected override async Task SendAsync(HttpRequestMessage var rq = builder.Build(); var call = client.NewCall(rq); - cancellationToken.Register(() => call.Cancel()); + + // NB: Even closing a socket must be done off the UI thread. Cray! + cancellationToken.Register(() => Task.Run(() => call.Cancel())); var resp = default(Response); try {