结束进程并等待结束
This commit is contained in:
parent
2956fa406a
commit
a1e4aed2dc
@ -59,23 +59,7 @@ namespace FastGithub.Dns
|
|||||||
this.socket.IOControl(SIO_UDP_CONNRESET, new byte[4], new byte[4]);
|
this.socket.IOControl(SIO_UDP_CONNRESET, new byte[4], new byte[4]);
|
||||||
}
|
}
|
||||||
this.socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
this.socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
||||||
|
this.socket.Bind(new IPEndPoint(address, port));
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -34,7 +34,9 @@ namespace FastGithub.Dns
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Process.GetProcessById(pid).Kill();
|
var proess = Process.GetProcessById(pid);
|
||||||
|
proess.Kill();
|
||||||
|
proess.WaitForExit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
|
|||||||
@ -34,7 +34,9 @@ namespace FastGithub.ReverseProxy
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Process.GetProcessById(pid).Kill();
|
var proess = Process.GetProcessById(pid);
|
||||||
|
proess.Kill();
|
||||||
|
proess.WaitForExit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user