sc 1 month ago
parent
commit
395f066568
  1. 35
      Class/HttpServer.cs

35
Class/HttpServer.cs

@ -99,6 +99,7 @@ namespace SunlightAggregationTerminal.Class
}
/***发送信息处理***/
private static int HttpOutN=0;
public static async void HttpTransmit(string Dat)
{
if (!httpclient.Online) //检查连接
@ -123,7 +124,7 @@ namespace SunlightAggregationTerminal.Class
.AsPost();
// 创建一个超时操作,15秒后取消
using var cts = new CancellationTokenSource(1000 * 15);
using var cts = new CancellationTokenSource(1000 * 10);
try
{
using (var responseResult = await httpclient.RequestAsync(request, cts.Token))
@ -136,18 +137,36 @@ namespace SunlightAggregationTerminal.Class
}
catch (OperationCanceledException)
{
// 专门处理超时或主动取消的情况
MainThread.BeginInvokeOnMainThread(() =>
if (HttpOutN >= 3)
{
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", "网络请求超时,请检查网络网络连接", "是");
});
HttpOutN = 0;
// 专门处理超时或主动取消的情况
MainThread.BeginInvokeOnMainThread(() =>
{
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", "网络请求超时,请检查网络网络连接", "是");
});
}
else
{
HttpTransmit(Dat);//回调
HttpOutN++;
}
}
catch (Exception ex)
{
MainThread.BeginInvokeOnMainThread(() =>
if (HttpOutN >= 3)
{
Application.Current!.Windows[0].Page!.DisplayAlertAsync("访问错误", ex.Message.ToString(), "是");
});
HttpOutN = 0;
MainThread.BeginInvokeOnMainThread(() =>
{
Application.Current!.Windows[0].Page!.DisplayAlertAsync("访问错误", ex.Message.ToString(), "是");
});
}
else
{
HttpTransmit(Dat);//回调
HttpOutN++;
}
}
finally
{

Loading…
Cancel
Save