Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightAggregationTerminal
This commit is contained in:
commit
70dabd0ca6
7 files changed
+109
-35
No files matched your search
+35
-6
@@ -91,10 +91,12 @@ namespace SunlightAggregationTerminal.Class
|
||||
/***发送信息处理***/
|
||||
public static async void HttpTransmit(string Dat)
|
||||
{
|
||||
if(!httpclient.Online) //检查连接
|
||||
if (!httpclient.Online) //检查连接
|
||||
{
|
||||
await httpclient.ConnectAsync();
|
||||
await httpclient.ConnectAsync();
|
||||
}
|
||||
Dispose();
|
||||
|
||||
var dat = new DataReceived.Person()
|
||||
{
|
||||
User = DataReceived.ServerName,
|
||||
@@ -121,7 +123,6 @@ namespace SunlightAggregationTerminal.Class
|
||||
// GetBodyAsync 同样需要响应取消信号,如果这里超过剩余时间也会抛出异常
|
||||
var result = await response.GetBodyAsync();
|
||||
DataReceived.Received(result);
|
||||
//await httpclient.CloseAsync();//关闭客户端
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
@@ -131,7 +132,6 @@ namespace SunlightAggregationTerminal.Class
|
||||
{
|
||||
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", "网络请求超时,请检查网络网络连接", "是");
|
||||
});
|
||||
await httpclient.CloseAsync();//关闭客户端
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -140,8 +140,37 @@ namespace SunlightAggregationTerminal.Class
|
||||
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", ex.Message.ToString(), "是");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
finally
|
||||
{
|
||||
Start();
|
||||
}
|
||||
}
|
||||
|
||||
//倒计时5秒关闭http客户端
|
||||
private static Timer? _timer;
|
||||
private static bool _isDisposed = false;
|
||||
private static void Start()
|
||||
{
|
||||
// 延迟30秒后执行一次,不自动循环
|
||||
_timer = new Timer(Httpout, null, TimeSpan.FromSeconds(5), Timeout.InfiniteTimeSpan);
|
||||
}
|
||||
private static async void Dispose()
|
||||
{
|
||||
if (!_isDisposed)
|
||||
{
|
||||
_isDisposed = true;
|
||||
_timer?.Dispose(); // 释放定时器资源
|
||||
_timer = null;
|
||||
}
|
||||
}
|
||||
private static async void Httpout(object? state)
|
||||
{
|
||||
if (httpclient.Online)
|
||||
{
|
||||
await httpclient.CloseAsync();
|
||||
}
|
||||
Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user