我看到 System.Diagnostics.Process.HasExited
方法抛出 InvalidOperationException
,但消息文本属性对于抛出它的原因并不是很有用。在什么情况下会抛出此异常?
最佳答案
我看到了同样的消息。如果您这样做,可能会发生这种情况:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "trash filename here.exe";
try
{
proc.Start();
}
catch { }//proc should fail.
try
{
if (proc.HasExited)
{
//....
}
}
catch (System.InvalidOperationException e)
{
//cry and weep about it here.
}
如果上面的 proc.Start()
失败,您也应该哭泣。因此,如果您在 proc.Start()
之后捕获,请务必在 proc.HasExited
(以及许多其他 System.Diagnostics.Process
方法。
关于c# - Process.HasExited 抛出 InvalidOperationException 的原因是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2603296/