private void callMethod(object args) { lock (locker) { try { startProcess(args as string[]); ExitedEventArgs exitedArgs = errorBuilder.Length > 0 ? new ExitedEventArgs(outputBuilder.ToString(), errorBuilder.ToString()) : new ExitedEventArgs(outputBuilder.ToString()); if (this.Exited != null) { this.Exited(this, exitedArgs); } } finally { outputBuilder.Clear(); errorBuilder.Clear(); } } }
protected virtual void OnExited(ExitedEventArgs e) { ExitedEventHandler handler = Exited; handler?.Invoke(this, e); }
private void Monitor() { WaitHandle.WaitAny(new[] { processEvent, stopEvent }); if (disposed == false) { lock (stateLock) { if (started) { GetExitCodeProcessExitCode exitCode; if (!PInvoke.Processes.Functions.GetExitCodeProcess(process, out exitCode)) { throw new PInvokeException("Unable to get process exit code"); } if (exitCode != GetExitCodeProcessExitCode.STATUS_PENDING) { started = false; var eventArgs = new ExitedEventArgs { ExitCode = exitCode }; if (Exited != null) { Exited(this, eventArgs); } } } } } }
public static void DisplayExitCode(object sender, ExitedEventArgs e) { Console.WriteLine("ExitCode : {0}", e.ExitCode); }