I had a similar problem: my application is essentially an interface for some cygwin applications, and sometimes the application exits all the data received through the OutputDataReceived event, and I lose data.
My fix / hack is to call WaitUtilEOF on the AsyncStreamReader output before the process object disappears (you need to use reflection, since WaitUtilEOF is in the inner class of the .NET platform). This results in the caller being blocked until all asynchronization data has been cleared through OutputDataReceived. I am not sure if it will directly solve your problem, but it may help ...
private static void WaitUntilAsyncStreamReachesEndOfFile(Process process, string field) { FieldInfo asyncStreamReaderField = typeof(Process).GetField(field, BindingFlags.NonPublic | BindingFlags.Instance); object asyncStreamReader = asyncStreamReaderField.GetValue(process); Type asyncStreamReaderType = asyncStreamReader.GetType(); MethodInfo waitUtilEofMethod = asyncStreamReaderType.GetMethod(@"WaitUtilEOF", BindingFlags.NonPublic | BindingFlags.Instance); object[] empty = new object[] { }; waitUtilEofMethod.Invoke(asyncStreamReader, empty); }
And I call it this way:
WaitUntilAsyncStreamReachesEndOfFile(process, "output");
Good luck
user147652
source share