Researching I found out that Background Worker
is a background thread
, however when I run the following code Background Worker
still runs until the end even when the main procedure is exited. Isn't this feature reserved to foreground threads
?
Code:
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