mirror of
https://github.com/netchx/netch.git
synced 2026-05-09 22:54:03 +08:00
Update Guard
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.Threading;
|
||||
@@ -56,13 +55,6 @@ public abstract class Guard
|
||||
|
||||
public Process Instance { get; }
|
||||
|
||||
~Guard()
|
||||
{
|
||||
_logFileStream?.Dispose();
|
||||
_logStreamWriter?.Dispose();
|
||||
Instance.Dispose();
|
||||
}
|
||||
|
||||
protected async Task StartGuardAsync(string argument, ProcessPriorityClass priority = ProcessPriorityClass.Normal)
|
||||
{
|
||||
State = State.Starting;
|
||||
@@ -129,8 +121,6 @@ public abstract class Guard
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
State = State.Stopped;
|
||||
}
|
||||
|
||||
public virtual Task StopAsync()
|
||||
@@ -140,9 +130,6 @@ public abstract class Guard
|
||||
|
||||
protected async Task StopGuardAsync()
|
||||
{
|
||||
_logStreamWriter?.Close();
|
||||
_logFileStream?.Close();
|
||||
|
||||
try
|
||||
{
|
||||
if (Instance is { HasExited: false })
|
||||
@@ -151,13 +138,21 @@ public abstract class Guard
|
||||
await Instance.WaitForExitAsync();
|
||||
}
|
||||
}
|
||||
catch (Win32Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e, "Stop {Name} failed", Instance.ProcessName);
|
||||
}
|
||||
catch
|
||||
finally
|
||||
{
|
||||
// ignored
|
||||
if (_logStreamWriter != null)
|
||||
await _logStreamWriter.DisposeAsync();
|
||||
|
||||
if (_logFileStream != null)
|
||||
await _logFileStream.DisposeAsync();
|
||||
|
||||
Instance.Dispose();
|
||||
|
||||
State = State.Stopped;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user