Skip to content

Commit

Permalink
Always cancel on the UI thread. Fixes #96
Browse files Browse the repository at this point in the history
  • Loading branch information
anaisbetts committed Oct 16, 2014
1 parent ffdb1c4 commit 7de225e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ModernHttpClient/Android/OkHttpNetworkHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Java.IO;
using System.Security.Cryptography.X509Certificates;
using System.Globalization;
using Android.OS;

namespace ModernHttpClient
{
Expand Down Expand Up @@ -85,7 +86,9 @@ protected override async Task<HttpResponseMessage> 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 {
Expand Down

0 comments on commit 7de225e

Please sign in to comment.