diff --git a/UserClass/AsyncTcpClient.cs b/UserClass/AsyncTcpClient.cs index 5652b5b..384afb4 100644 --- a/UserClass/AsyncTcpClient.cs +++ b/UserClass/AsyncTcpClient.cs @@ -7,7 +7,6 @@ using System.Text.Json; using TouchSocket.Core; using TouchSocket.Sockets; using static SunlightAggregationManager.UserClass.AsyncTcpServer; -using static System.Runtime.InteropServices.JavaScript.JSType; namespace SunlightAggregationManager.UserClass { @@ -58,7 +57,16 @@ namespace SunlightAggregationManager.UserClass Console.WriteLine("Sunlight_Server_Connected"); return EasyTask.CompletedTask; };//成功连接到服务器 - tcpClient.Closing = (client, e) => { return EasyTask.CompletedTask; };//即将从服务器断开连接。此处仅主动断开才有效。 + tcpClient.Closing = (client, e) => { + System.Data.DataRow targetRow = ViewModel.MainWindowViewModel._service.Select("Service = 'Sunlight_Server_Link'").FirstOrDefault()!; + if (targetRow != null) + { + targetRow.BeginEdit(); + targetRow["Status"] = "Disconnect"; + targetRow.EndEdit(); + } + Console.WriteLine("Sunlight_Server_Disconnect"); + return EasyTask.CompletedTask; };//即将从服务器断开连接。此处仅主动断开才有效。 tcpClient.Closed = (client, e) => { System.Data.DataRow targetRow = ViewModel.MainWindowViewModel._service.Select("Service = 'Sunlight_Server_Link'").FirstOrDefault()!; if (targetRow != null) @@ -130,7 +138,7 @@ namespace SunlightAggregationManager.UserClass { a.UseReconnection(options => { - options.PollingInterval = TimeSpan.FromSeconds(5); + options.PollingInterval = TimeSpan.FromSeconds(3); }); })); @@ -145,6 +153,7 @@ namespace SunlightAggregationManager.UserClass public static async void CommandC(string dat, Person person)// { + try { string Command = "", ret = ""; Dictionary data_ = new Dictionary(); @@ -208,6 +217,12 @@ namespace SunlightAggregationManager.UserClass person!.Dat = ret.ToString(); var jsdat = JsonSerializer.Serialize(person); await tcpClient.SendAsync(jsdat); + } + catch (Exception ex) + { + LogGing.ERRDATA(ex); + Console.WriteLine(ex.ToString()); + } } } }