SocketAsyncResult.CheckIfThrowDelayedException()System.Net.Sockets.SocketException:网络子系统在Xamarin.Android应用中关闭

时间:2019-04-25 05:42:48

标签: c# xamarin xamarin.android httpclient

我正在开发Xamarin.Android App。当应用程序位于前台时,HTTP调用可以正常工作。但是我最近观察到,当应用程序在后台运行并在10-15分钟后进入前台时,' SocketAsyncResult.CheckIfThrowDelayedException() System.Net.Sockets.SocketException:网络子系统已关闭

堆栈跟踪:

HttpClientHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
HttpClient.SendAsyncWorker (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken)
ASAPService.GetBookingDetails (System.String bookingID)
TrackViewModel.GetBookingStatus (System.String bookingDetails)
TrackActivity.<InitializeLocalVariables>b__46_0 (System.Object e)
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_1 (System.Object state)
QueueUserWorkItemCallback.WaitCallback_Context (System.Object state)
ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx)
ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx)
IThreadPoolWorkItem.ExecuteWorkItem ()
ThreadPoolWorkQueue.Dispatch ()
_ThreadPoolWaitCallback.PerformWaitCallback ()

看到一些帖子后,我尝试使用ModernHttpClient,但是我得到了 NativeMessageHandler.SendAsync(System.Net.Http.HttpRequestMessage请求,System.Threading.CancellationToken cancelledToken) Java.IO.IOException:超时“异常。”

我在项目属性中将HTTP客户端实现更改为 Android ,并将SSL / TLS实现更改为“本机TLS 1.2+”。但是没有任何帮助。

这是应用程序进入前台时调用的代码。

HttpClient client = new HttpClient();

string Url = String.Format(BASE_ASAP_CUSTOMER_URL + AppConstants.BookingStatus + "AppConstants.BookingParam", bookingID);
 client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppGlobal.Token);

using (HttpResponseMessage response = await client.GetAsync(Url))
 using (HttpContent content = response.Content)
 {
  string result = await content.ReadAsStringAsync();
  var bookingStatus =JsonConvert.DeserializeObject<BookingStatusEntity(result);

return bookingStatus;

0 个答案:

没有答案