async Task CaptureOutput() { char [] buffer = new char [1024]; int nr; while ((nr = await StandardOutput.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) > 0) { OutputStreamChanged?.Invoke(this, new string (buffer, 0, nr)); } }
private async Task CaptureOutput() { try { if (OutputStreamChanged != null) { char[] buffer = new char [1024]; int nr; while ((nr = await StandardOutput.ReadAsync(buffer, 0, buffer.Length)) > 0) { OutputStreamChanged?.Invoke(this, new string (buffer, 0, nr)); } } } catch (ThreadAbortException) { // There is no need to keep propagating the abort exception Thread.ResetAbort(); } finally { // WORKAROUND for "Bug 410743 - wapi leak in System.Diagnostic.Process" // Process leaks when an exit event is registered if (endEventErr != null) { endEventErr.WaitOne(); } try { if (HasExited) { operation.ExitCode = ExitCode; } } catch { // Ignore } try { OnExited(this, EventArgs.Empty); } catch { // Ignore } lock (lockObj) { //call this AFTER the exit event, or the ProcessWrapper may get disposed and abort this thread if (endEventOut != null) { endEventOut.Set(); } } taskCompletionSource.SetResult(operation.ExitCode); } }