【发布时间】:2013-07-22 05:44:23
【问题描述】:
研究我发现Background Worker 是background thread,但是当我运行下面的代码Background Worker 时,即使退出了主程序,它仍然会运行到最后。这个功能不是保留给foreground threads吗?
代码:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Run background worker
BackgroundWorker1.RunWorkerAsync()
'Display exit message
MsgBox("Main procedure exited")
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
'Wait 10 seconds
Threading.Thread.Sleep(10000)
'Modify some numbers
Dim variable = 3
variable -= 1
'Display exit message
MsgBox("Background thread " & variable & " exited")
End Sub
End Class
【问题讨论】:
标签: vb.net multithreading backgroundworker background-thread