mirror of
https://github.com/netchx/netch.git
synced 2026-03-18 18:13:21 +08:00
Revert "Fix Guard close file"
This commit is contained in:
@@ -61,6 +61,13 @@ namespace Netch.Controllers
|
||||
|
||||
public Process Instance { get; }
|
||||
|
||||
~Guard()
|
||||
{
|
||||
_logFileStream?.Dispose();
|
||||
_logStreamWriter?.Dispose();
|
||||
Instance.Dispose();
|
||||
}
|
||||
|
||||
protected async Task StartGuardAsync(string argument, ProcessPriorityClass priority = ProcessPriorityClass.Normal)
|
||||
{
|
||||
State = State.Starting;
|
||||
@@ -77,12 +84,8 @@ namespace Netch.Controllers
|
||||
|
||||
if (RedirectOutput)
|
||||
{
|
||||
WaitAllReadOutputTaskAsync(new[]
|
||||
{
|
||||
ReadOutputAsync(Instance.StandardOutput),
|
||||
ReadOutputAsync(Instance.StandardError)
|
||||
})
|
||||
.Forget();
|
||||
Task.Run(() => ReadOutput(Instance.StandardOutput)).Forget();
|
||||
Task.Run(() => ReadOutput(Instance.StandardError)).Forget();
|
||||
|
||||
if (!StartedKeywords.Any())
|
||||
{
|
||||
@@ -112,21 +115,12 @@ namespace Netch.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
private async Task WaitAllReadOutputTaskAsync(Task[] tasks)
|
||||
{
|
||||
await Task.WhenAll(tasks);
|
||||
_logStreamWriter?.Close();
|
||||
_logFileStream?.Close();
|
||||
Instance.Dispose();
|
||||
State = State.Stopped;
|
||||
}
|
||||
|
||||
private async Task ReadOutputAsync(TextReader reader)
|
||||
private void ReadOutput(TextReader reader)
|
||||
{
|
||||
string? line;
|
||||
while ((line = await reader.ReadLineAsync()) != null)
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
await _logStreamWriter!.WriteLineAsync(line);
|
||||
_logStreamWriter!.WriteLine(line);
|
||||
OnReadNewLine(line);
|
||||
|
||||
if (State == State.Starting)
|
||||
@@ -140,6 +134,8 @@ namespace Netch.Controllers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
State = State.Stopped;
|
||||
}
|
||||
|
||||
public virtual async Task StopAsync()
|
||||
@@ -149,6 +145,9 @@ namespace Netch.Controllers
|
||||
|
||||
protected async Task StopGuardAsync()
|
||||
{
|
||||
_logStreamWriter?.Close();
|
||||
_logFileStream?.Close();
|
||||
|
||||
try
|
||||
{
|
||||
if (Instance is { HasExited: false })
|
||||
|
||||
Reference in New Issue
Block a user