使用c#调用外部.exe时出现问题

hik*_*ume 0 c# exe

我正在尝试从我的c#代码运行这个.exe文件,它确实调用.exe文件,但随后它在中途崩溃.如果我点击浏览器上的.exe就可以完成它的工作,所以我想知道我用来调用它的代码是否有问题:

            string fileName =  "loadscript.exe";
            Utils.Logger.Info("Calling script:" + fileName);
            Process process = new Process();
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.FileName = fileName;
            process.StartInfo.RedirectStandardOutput = true;
            process.Start();
            Thread.Sleep(10000);
            process.WaitForExit();
            int exitCode = process.ExitCode;
            string output = process.StandardOutput.ReadToEnd();
            Utils.Logger.Info(".exe Output: ");
            Utils.Logger.Info(output);
Run Code Online (Sandbox Code Playgroud)

Can*_*cer 5

  Thread.Sleep(10000);
  process.WaitForExit();
  int exitCode = process.ExitCode;
  string output = process.StandardOutput.ReadToEnd();
Run Code Online (Sandbox Code Playgroud)

在我看来,这样做会造成死锁,这可能是最终崩溃的问题.取消睡眠并尝试这样做:

  string output = process.StandardOutput.ReadToEnd();
  process.WaitForExit();
  int exitCode = process.ExitCode;
Run Code Online (Sandbox Code Playgroud)

请参阅此问题的答案以获得解释:

重定向输出时ResGen.exe卡住了