Skip to content

Commit 63dfb1a

Browse files
committed
Always cancel off the UI thread. Fixes #96
1 parent ffdb1c4 commit 63dfb1a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/ModernHttpClient/Android/OkHttpNetworkHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Java.IO;
1212
using System.Security.Cryptography.X509Certificates;
1313
using System.Globalization;
14+
using Android.OS;
1415

1516
namespace ModernHttpClient
1617
{
@@ -85,7 +86,9 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
8586

8687
var rq = builder.Build();
8788
var call = client.NewCall(rq);
88-
cancellationToken.Register(() => call.Cancel());
89+
90+
// NB: Even closing a socket must be done off the UI thread. Cray!
91+
cancellationToken.Register(() => Task.Run(() => call.Cancel()));
8992

9093
var resp = default(Response);
9194
try {

0 commit comments

Comments
 (0)