anycmd 4 years ago
parent
commit
ac6ecd8cb2
1 changed files with 8 additions and 0 deletions
  1. 8 0
      src/NTMinerDaemon/Ws/AbstractWsClient.cs

+ 8 - 0
src/NTMinerDaemon/Ws/AbstractWsClient.cs

@@ -1,5 +1,6 @@
 using NTMiner.User;
 using System;
+using System.Net.NetworkInformation;
 using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
@@ -107,6 +108,13 @@ namespace NTMiner.Ws {
             VirtualRoot.BuildEventPath<AppExitEvent>("退出程序时关闭Ws连接", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, path: message => {
                 _ws?.CloseAsync(CloseStatusCode.Normal, "客户端程序退出");
             });
+            NetworkChange.NetworkAvailabilityChanged += (object sender, NetworkAvailabilityEventArgs e) => {
+                if (e.IsAvailable) {
+                    1.SecondsDelay().ContinueWith(t => {
+                        OpenOrCloseWs(isResetFailCount: true);
+                    });
+                }
+            };
             /// 1,进程启动后第一次连接时;
             NeedReWebSocket();
             OpenOrCloseWs();