我正在调用一个第三部分的应用程序,它‘有时’在VB.NET中工作(它是一个自托管的WCF)。但有时第三方应用会永远挂起,所以我给它加了一个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有什么想法吗?
谢谢,
杰森
发布于 2011-06-15 00:16:30
检查方法返回值- http://msdn.microsoft.com/en-us/library/ty0d8k56.aspx -如果调用超时,将返回False。
发布于 2011-06-15 00:22:13
在过去,已经有一些已知的问题,应用程序在使用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/en-us/library/system.diagnostics.process.standardoutput.aspx
发布于 2013-02-06 15:32:52
if(process.WaitForExit(timeout)) {
// user exited
} else {
// timeout (perhaps process.Kill();)
}https://stackoverflow.com/questions/6346651
复制相似问题