protected virtual void InitializeEvents() { _process.OutputDataReceived += (sender, args) => { if (args.Data != null) { OnOutputDataReceived?.Invoke(sender, args.Data); } }; _process.ErrorDataReceived += (sender, args) => { if (args.Data != null) { OnErrorDataReceived?.Invoke(sender, args.Data); } }; _process.Exited += (sender, _) => { if (sender is Process process) { OnExited?.Invoke(sender, process.ExitCode); } else { OnExited?.Invoke(sender, _process.ExitCode); } }; }
public Action <IReference> CreateOnExited(Action <IReference> onExited) { return((IReference reference) => { onExited?.Invoke(reference); OnExited?.Invoke(reference); }); }
/// <summary> /// 等待进程退出 /// </summary> /// <param name="millisec">要等待的毫秒数,-1为无限等待</param> /// <param name="nativeWait">是否直接使用WaitForSingleObject等待</param> public int?WaitForExit(int millisec, bool nativeWait) { if (nativeWait) { int rslt = WaitForSingleObject(NativeProcessHandle.DangerousGetHandle(), millisec); ThrowExceptionByCode(rslt); if (GetExitCodeProcess(NativeProcessHandle.DangerousGetHandle(), out var exitCode)) { if (exitCode == 0) { OnExited?.Invoke(exitCode); } else { OnExitCodeNonZero?.Invoke(exitCode); } NativeProcessHandle = null; return(exitCode); } OnExited?.Invoke(null); NativeProcessHandle = null; return(null); } CurrentProcess.WaitForExit(millisec); NativeProcessHandle = null; return(CurrentProcess.ExitCode); }
private void Awake() { State.OnTransitionIn += (_) => OnTransitionIn.Invoke(); State.OnTransitionOut += (_) => OnTransitionOut.Invoke(); State.OnEntered += (_) => OnEntered.Invoke(); State.OnExited += (_) => OnExited.Invoke(); }
public async Task <int> ExecuteCommand(string command, string args, CancellationToken token) { var processInfo = new ProcessStartInfo(command, args); processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; processInfo.WindowStyle = ProcessWindowStyle.Hidden; processInfo.RedirectStandardError = true; processInfo.RedirectStandardOutput = true; int exitCode; using (var process = new Process()) { process.StartInfo = processInfo; process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => OnConsoleRunnerDataReceived?.Invoke(sender, e.Data); process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => OnConsoleRunnerErrorDataReceived?.Invoke(sender, e.Data); process.Exited += (object sender, EventArgs e) => { OnExited?.Invoke(sender, e); }; try { var processStarted = process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); await Task.Run(() => process.WaitForExit(), token); process.CancelOutputRead(); process.CancelErrorRead(); } catch (OperationCanceledException ex) { process.CancelOutputRead(); process.CancelErrorRead(); process.Kill(); } finally { exitCode = process.ExitCode; process.Close(); } } return(exitCode); }
private void ThriftRpcProcess_Exited(object sender, EventArgs e) { Process proc = (Process)sender; if (proc.ExitCode == 0) { ThriftRpcLog.Info("Thrift RPC Agent has terminated with exit code 0"); } else { ThriftRpcLog.Fatal($"Thrift RPC Agent has exited abnormally with exit code {proc.ExitCode}"); } OnExited?.Invoke(this, EventArgs.Empty); }
protected async Task HandleExitedAsync(IReference refback) { // No need for transitions when the component is hidden var transition = string.Empty; var styles = new Dictionary <string, object> { { "transition", transition }, { "webkitTransition", transition } }; await DomHelpers.SetStyleAsync(refback.Current, styles, trigger : false); OnExited?.Invoke(refback); }
private void OnCompilerExited(object sender, EventArgs e) { // release process var cl = (Process)sender; if (cl.ExitCode == 0) { _compileErrors.Clear(); } cl.OutputDataReceived -= OnCompilerOutputDataReceived; cl.ErrorDataReceived -= OnCompilerOutputDataReceived; cl.Exited -= OnCompilerExited; cl.Dispose(); IsBusy = false; OnExited?.Invoke(_compileErrors, _compileWarnings); }
public void DrawMenu() { OnEntered?.Invoke(this); MenuLogicHelper.CopyEvents(this); _needsRedraw = true; _open = true; while (_open) { if (!_needsRedraw) { //Only check the hashes if we are not already redrawing _needsRedraw = HashHelper.NeedsToRedraw(_lastDrawnHash, this); } if (_needsRedraw) { Console.Clear(); MenuLogicHelper.DrawContents(this); _needsRedraw = false; _lastDrawnHash = HashHelper.MakeHash(this); } if (!Console.KeyAvailable) { continue; } var key = Console.ReadKey(true); if (key.Key == ConsoleKey.Escape) { break; } MenuLogicHelper.ProcessKey(this, key); _needsRedraw = true; } OnExited?.Invoke(this); }
protected async Task PerformExit() { if (!(Exit.HasValue && Exit.Value)) { Current = TransitionState.Exited; // TODO: need to check Next = TransitionState.None; await LocalStateHasChanged(); await(OnExited?.Invoke(RefBack) ?? Task.CompletedTask); return; } Current = TransitionState.Exit; await LocalStateHasChanged(); await(OnExit?.Invoke(RefBack) ?? Task.CompletedTask); Current = TransitionState.Exiting; await LocalStateHasChanged(); await(OnExiting?.Invoke(RefBack) ?? Task.CompletedTask); await OnTransitionEnd(async() => { Current = UnmountOnExit ? TransitionState.Unmounted : TransitionState.Exited; // TODO: need to check Next = TransitionState.None; await LocalStateHasChanged(force: UnmountOnExit); await(OnExited?.Invoke(RefBack) ?? Task.CompletedTask); }, TimeoutExit); }
protected void HandleExited(IReference refback) { OnExited?.Invoke(refback); }
protected virtual void RaiseOnExited() { OnExited?.Invoke(); }
protected void OnStop() { IsRunning = false; OnExited?.Invoke(); }
public void Exit() { OnExited?.Invoke(); }
public void Eject(T pieceToMove) { EjectInternal(pieceToMove); OnExited?.Invoke(pieceToMove); }
private void Process_Exited(object sender, EventArgs e) { OnExited?.Invoke(this, process.ExitCode); Dispose(); }