vb.net - If Background Worker is a background thread how come I can executed this code? -
researching found out background worker
background thread
, when run following code background worker
still runs until end when main procedure exited. isn't feature reserved foreground threads
?
code:
public class form1 private sub form1_load(sender object, e eventargs) handles mybase.load 'run background worker backgroundworker1.runworkerasync() 'display exit message msgbox("main procedure exited") end sub private sub backgroundworker1_dowork(sender object, e system.componentmodel.doworkeventargs) handles backgroundworker1.dowork 'wait 10 seconds threading.thread.sleep(10000) 'modify numbers dim variable = 3 variable -= 1 'display exit message msgbox("background thread " & variable & " exited") end sub end class
the form1_load
method not "main procedure", message box you're displaying @ end of lie. that's event handler method form.load
event, raised when form being displayed first time.
the "main procedure" named main
, defined in separate file (actually, in vb.net, it's automatically generated compiler , not visible default). can find more information on main
method in microsoft's vb programming guide.
the main
method still running long program still running. after form1_load
event handler method finishes, form1
still on screen, program hasn't closed yet. , since program's main thread still running, backgroundworker
object's background thread still running, asynchronously, told to.
Comments
Post a Comment