I have a windows service calling a console application and reads the console output to figure out the status.
I am calling WaitForExit() with a time limit after calling StandardOutput.ReadToEnd().
The question is in cases where the console application takes more time than the time limit for WaitForExit(), then will ReadToEnd() block till the executable has exited making WaitForExit() redundant ?
Process process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = pathToExecutable,
Arguments = args,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
};
process.Start();
// Adding ReadToEnd() before the WaitForExit() call to prevent deadlocks in case Process buffer size becomes full
// Ref: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.standardoutput?redirectedfrom=MSDN&view=netframework-4.5.2#remarks
response = process.StandardOutput.ReadToEnd();
process.WaitForExit(waitForExitInSeconds * 1000);
process.Close();
// Read response string and determine status