如何使用Process.WaitForExit

| 我正在调用一个“有时”在VB.NET中运行的第三部分应用程序(这是一个自托管的WCF)。但是有时第3方应用程序将永远挂起,因此我为其添加了90秒计时器。问题是,我怎么知道事情是否超时? 代码如下:
Dim MyProcess as System.Diagnostics.Process = System.Diagnostics.Process.Start(MyInfo)
MyProcess.WaitForExit(90000)
我想做的是这样的
If MyProcess.ExceededTimeout Then
    MyFunction = False
Else
    MyFunction = True
End If
有任何想法吗? 谢谢, 杰森     
已邀请:
        检查方法的返回值-http://msdn.microsoft.com/zh-cn/library/ty0d8k56.aspx-如果调用超时,它将返回False。     
        过去存在一些已知问题,使用WaitForExit时应用程序将冻结。 您需要使用
dim Output as String = MyProcess.StandardOutput.ReadToEnd()
打电话之前
MyProcess.WaitForExit(90000)
请参阅Microsoft的代码段:
// Start the child process.
 Process p = new Process();
 // Redirect the output stream of the child process.
 p.StartInfo.UseShellExecute = false;
 p.StartInfo.RedirectStandardOutput = true;
 p.StartInfo.FileName = \"Write500Lines.exe\";
 p.Start();
 // Do not wait for the child process to exit before
 // reading to the end of its redirected stream.
 // p.WaitForExit();
 // Read the output stream first and then wait.
 string output = p.StandardOutput.ReadToEnd();
 p.WaitForExit();
http://msdn.microsoft.com/zh-CN/library/system.diagnostics.process.standardoutput.aspx     
        
if(process.WaitForExit(timeout)) {
    // user exited
} else {
    // timeout (perhaps process.Kill();)
}
异步进程开始并等待其完成     

要回复问题请先登录注册