【发布时间】:2013-10-27 13:27:37
【问题描述】:
我在 using 行的 try-catch 中设置了一个断点。另一个在result.wasSuccessful 行。
当我这样做时,它会转到 catch 并说它返回一个错误。
但是,当using 行没有断点时,不会捕获任何错误。
为什么会这样?
这是错误
+ $exception {"Cannot process request because the process (12400) has exited."} System.Exception {System.InvalidOperationException}
try
{
using (Process exeProcess = Process.Start(psi))
{
exeProcess.PriorityClass = ProcessPriorityClass.High;
var outString = new StringBuilder(100);
exeProcess.OutputDataReceived += (s, e) => outString.AppendLine(e.Data);
exeProcess.BeginOutputReadLine();
var errString = exeProcess.StandardError.ReadToEnd();
if (!string.IsNullOrEmpty(errString))
{
result.WasSuccessful = false;
result.ErrorMessage = errString;
}
}
}
catch (Exception ex)
{
result.WasSuccessful = false;
result.ErrorMessage = ex.ToString();
}
【问题讨论】:
-
看起来是时间问题
-
您正在启动另一个进程。 Visual Studio 调试器能够冻结当前进程的执行并逐行(跨多个线程)逐步执行,但它与您正在启动的进程不同,因为它没有附加。也许你不应该调用静态方法
Process.Start,而只是创建一个new Process(),然后设置它的属性,然后最后调用process.Start(),也许是process.WaitForExit()(实例方法)?
标签: c# visual-studio-2010