我正在创建一个新的Systems.Diagnostics对象:
System.Diagnostics.Process androidProcess= new System.Diagnostics.Process();
但是我的代码会导致InvalidOperationException异常,我不明白为什么。
BasePriority = 'androidProcess.BasePriority' threw an exception of type 'System.InvalidOperationException'
ExitCode = 'androidProcess.ExitCode' threw an exception of type 'System.InvalidOperationException'
ExitTime = 'androidProcess.ExitTime' threw an exception of type 'System.InvalidOperationException'为什么我的代码会产生这些异常?
提前谢谢。
发布于 2011-05-09 11:15:43
问题是,在进程启动之前,无法访问这些属性中包含的值。在进程启动之前,它没有进程ID或与其关联的句柄。
属性的文档确认这一点,指示在以下条件之一下抛出InvalidOperationException:
解决方案是启动您首先创建的流程,然后根据需要获取这些属性。
发布于 2011-05-09 11:32:28
BasePriority、ExitTime和ExitCode是只读的。您不能设置这些属性。它们由CLR或已启动的进程本身设置。
请看一下MSDN:
https://stackoverflow.com/questions/5935967
复制相似问题