我看到一个System.Diagnositics.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.
}
Run Code Online (Sandbox Code Playgroud)
如果proc.Start()在上面失败了,你也应该哭泣和哭泣.所以,如果你抓住之后proc.Start()一定要抓住proc.HasExited(和许多其他的System.Diagnostics.Process方法.
正如Obalix正确指出的那样,InvalidOperationException当没有进程附加到Process对象时抛出a .当进程已退出和/ Close或Dispose已在Process对象上调用时,会发生这种情况.Close从内存中释放与进程相关的所有资源.在调用之前Close,这些数据保存在内存中,为您(程序员)提供您想要了解的有关已退出流程的信息,例如它ExitTime和ExitCode.
| 归档时间: |
|
| 查看次数: |
9726 次 |
| 最近记录: |