如果工作人员仍在忙于处理单个代码行,是否有任何方法可以在 x 秒后(即超时 5 秒)取消后台工作人员?(永远不要到 While 循环的末尾检查 CancellationPending)?例子:
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