瀏覽代碼

结束进程并等待结束

陈国伟 4 年之前
父節點
當前提交
a1e4aed2dc
共有 3 個文件被更改,包括 7 次插入19 次删除
  1. 1 17
      FastGithub.Dns/DnsServer.cs
  2. 3 1
      FastGithub.Dns/UdpTable.cs
  3. 3 1
      FastGithub.ReverseProxy/TcpTable.cs

+ 1 - 17
FastGithub.Dns/DnsServer.cs

@@ -59,23 +59,7 @@ namespace FastGithub.Dns
                 this.socket.IOControl(SIO_UDP_CONNRESET, new byte[4], new byte[4]);
             }
             this.socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
-
-            var maxSpinCount = 100;
-            var spinWait = new SpinWait();
-            var localEndPoint = new IPEndPoint(address, port);
-
-            for (var i = 0; i < maxSpinCount; i++)
-            {
-                try
-                {
-                    this.socket.Bind(localEndPoint);
-                    break;
-                }
-                catch (SocketException ex) when (ex.SocketErrorCode == SocketError.AccessDenied)
-                {
-                    spinWait.SpinOnce();
-                }
-            }
+            this.socket.Bind(new IPEndPoint(address, port));
         }
 
         /// <summary>

+ 3 - 1
FastGithub.Dns/UdpTable.cs

@@ -34,7 +34,9 @@ namespace FastGithub.Dns
 
             try
             {
-                Process.GetProcessById(pid).Kill();
+                var proess = Process.GetProcessById(pid);
+                proess.Kill();
+                proess.WaitForExit();
                 return true;
             }
             catch (ArgumentException)

+ 3 - 1
FastGithub.ReverseProxy/TcpTable.cs

@@ -34,7 +34,9 @@ namespace FastGithub.ReverseProxy
 
             try
             {
-                Process.GetProcessById(pid).Kill();
+                var proess = Process.GetProcessById(pid);
+                proess.Kill();
+                proess.WaitForExit();
                 return true;
             }
             catch (ArgumentException)