public void Start() { if (IsAlive) { return; } _thread = new Thread(() => { try { var startInfo = GetProcessStartInfo(); startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.RedirectStandardInput = true; using (var process = _processFactory.Start(startInfo)) { _childProcessTracker.Add(process); Process = process; var successTask = Task.Run(async() => { var stream = process.StandardOutput; while (!stream.EndOfStream) { var result = await stream.ReadLineAsync(); WarewolfLogger.Info(result, startInfo.FileName); } }); var errorTask = Task.Run(async() => { var stream = process.StandardError; while (!stream.EndOfStream) { var result = await stream.ReadLineAsync(); WarewolfLogger.Error(result, startInfo.FileName); } }); while (!process.WaitForExit(1000)) { // } Task.WaitAll(successTask, errorTask); OnProcessDied?.Invoke(Config); } } catch { } }) { IsBackground = true }; _thread.Start(); }
private void AddMissingMonitors() { foreach (var config in GetConfigs()) { if (_processLists.Exists(o => o.Config.Id == config.Id)) { continue; } var list = NewThreadList(config); list.OnProcessDied += (processDiedConfig) => OnProcessDied?.Invoke(processDiedConfig); _processLists.Add(list); } }