背景:私のアプリケーションは、 Selenium RCサーバーを使用してテストを実行するために使用されています。Selenium コマンドへの呼び出しが RC サーバーからの応答を返さないという問題が発生することがあります。テストを実行します。
サンプルコード:
Private Delegate Function DoCommand_Delegate(ByVal command As String, ByVal args() As String) As String
...
asyncCommand = New DoCommand_Delegate(AddressOf server.DoCommand)
asyncResult = asyncCommand.BeginInvoke(command, args, Nothing, Nothing)
Try
... (I have it use the AsyncWaitHandle to wait for periods of 10 seconds up to two minutes. At the end of each period it runs some checks for common problems that block Selenium from returning a response (modal dialogs) - I don't think that part is relevant to this question, it's just necessary.)
Finally
result = asyncCommand.EndInvoke(asyncResult)
...
が呼び出された時点EndInvoke
で、ワーカー デリゲートは既に終了しているか、中止する必要があります。ほとんどの場合、すでに応答があるため問題なく動作しますが、まれに Selenium RC のDoCommandが返されないため、スレッドがロックされたままになります。
最後に、私の質問:実行中のデリゲートを中止するためのリソースに優しい方法はありますか、それとも、中止して破棄できる手動で制御されたスレッドを使用するように変換する必要がありますか?
注:これは Selenium に関する質問ではなく、適切なマルチスレッドです。
注 2:をFinally
呼び出す前に、次のことを検討しました。EndInvoke
If Not asyncResult.IsCompleted Then asyncResult.AsyncWaitHandle.Close()
...しかし、それが実際に正しく機能するかどうか、またはどのような損傷を引き起こす可能性があるかはわかりません。