2

私は、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

何か案は?

ありがとう、

ジェイソン

4

3 に答える 3

5

過去に、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

于 2011-06-14T16:22:13.093 に答える
4

メソッドの戻り値(http://msdn.microsoft.com/en-us/library/ty0d8k56.aspx )を確認します。呼び出しがタイムアウトした場合は、Falseが返されます。

于 2011-06-14T16:16:29.580 に答える
2
if(process.WaitForExit(timeout)) {
    // user exited
} else {
    // timeout (perhaps process.Kill();)
}

非同期プロセスが開始し、終了するのを待ちます

于 2013-02-06T07:32:52.013 に答える