2 vb.net wcf process waitforexit
我正在调用第三方应用程序,它"有时"在VB.NET中运行(它是一个自托管的WCF).但有时第三方应用程序将永远挂起,所以我已经添加了一个90秒的计时器.问题是,我如何知道事情是否超时?
代码如下所示:
Dim MyProcess as System.Diagnostics.Process = System.Diagnostics.Process.Start(MyInfo)
MyProcess.WaitForExit(90000)
Run Code Online (Sandbox Code Playgroud)
我想做的就是这样
If MyProcess.ExceededTimeout Then
MyFunction = False
Else
MyFunction = True
End If
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
谢谢,
贾森
小智 5
过去已经存在一些问题,即使用WaitForExit时应用程序会冻结.
你需要使用
dim Output as String = MyProcess.StandardOutput.ReadToEnd()
Run Code Online (Sandbox Code Playgroud)
在打电话之前
MyProcess.WaitForExit(90000)
Run Code Online (Sandbox Code Playgroud)
请参阅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();
Run Code Online (Sandbox Code Playgroud)
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx