Beispiel #1
0
        private static async void BeginRead(Process process, StreamReader streamReader, StringReceivedEventHandler handler, CancellationToken cancel = default(CancellationToken))
        {
            while (!cancel.IsCancellationRequested)
            {
                string data = null;
                try
                {
                    data = await streamReader.ReadLineAsync().ConfigureAwait(false);
                }
                catch (ArgumentOutOfRangeException e)
                {
                    throw e;
                }
                catch (ObjectDisposedException)
                {
                    break; // Treat as EOF
                }
                catch (InvalidOperationException)
                {
                    // Try again next time
                }

                if ((data != null) && (handler != null))
                {
                    handler(process, data);
                }
                await Task.Delay(1).ConfigureAwait(false); // very important otherwise the error still occurs

                await Task.Yield();
            }
        }
Beispiel #2
0
 public static Process BeginErrorReadLine(this Process process, StringReceivedEventHandler handler, CancellationToken cancel = default(CancellationToken))
 {
     BeginRead(process, process.StandardError, handler, cancel);
     return(process);
 }