In Console Application, Windows 10, Visual Studio 2015, .NET 4.6 i call single method in Main called TestProcess. Build mode Debug, if I run app without debugging it prints correct text:
827ccb0eea8a706c4c34a16891f84e7b *test.txt
Press any key to continue . . .
If i run app with debugging it waits for 3 seconds before printing
Error False False False '' ''
This is just simplification of real problem, this code is backbone of some complex code which also hangs in release without debugging for md5sums.exe, but works for some other programs. Coplex code also also hangs on var a = proc.WaitForExit(timeout); until timeout as in attached example. On the other hand this simplification will work in release without debugger. Also, all this problems started with Windows 10, on Windows 7 it all worked fine.
[EDIT] Can't understand why would md5sums.exe cause problems, and if I use something else ie. FileName = "ping", Arguments = "localhost" everything works as expected.
[EDIT2] My complex program stopped working on Windows 10 (Release - Run without debugging), but this example hangs on Windows 7 also (Debug - Run with debugging)
static void TestProcess()
{
using (var proc = new Process())
{
proc.StartInfo.FileName = "md5sums.exe";
proc.StartInfo.WorkingDirectory = @"C:\Temp\ProcessDebug";
proc.StartInfo.Arguments = "-u test.txt";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
StringBuilder output = new StringBuilder();
StringBuilder error = new StringBuilder();
using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false))
{
proc.OutputDataReceived += (sender, e) =>
{
if (e.Data == null)
outputWaitHandle.Set();
else
output.AppendLine(e.Data);
};
proc.ErrorDataReceived += (sender, e) =>
{
if (e.Data == null)
errorWaitHandle.Set();
else
error.AppendLine(e.Data);
};
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
var timeout = 1000;
var a = proc.WaitForExit(timeout);
var b = outputWaitHandle.WaitOne(timeout);
var c = errorWaitHandle.WaitOne(timeout);
if (a && b && c)
Console.WriteLine(output.ToString());
else
Console.WriteLine($"Error {a} {b} {c} '{output}' '{error}'");
}
}
}