1

ワーカーがまだ単一のコード行の処理でビジーな場合、x 秒後 (つまり、タイムアウト 5 秒) にバックグラウンドワーカーをキャンセルする方法はありますか? (CancellationPending をチェックするために While ループの最後に行かないでください)? 例:

Private Sub DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
        Dim worker As BackgroundWorker = DirectCast(sender, BackgroundWorker)
        While Not worker.CancellationPending
            Dim args As ArgumentType = CType(e.Argument, ArgumentType)
            Try
            process #1
            process #2 --> hanging here. Never throw exception.
            ...
            process #n

            Catch ex as Exception
            'Never come here
            End Try
        End While
End Sub
4

1 に答える 1