J
Jason Kendall
I don't understand why the order of events happening here is
predictable.
Let's say I have a base class user control with a 'Load' event handler
and a sub:
Private Sub iMatterControlForm_Load(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Me.Load
Debug.WriteLine("BASE CLASS LOAD")
Me.BeginInvoke(New MethodInvoker(AddressOf TestOnLoad))
End Sub
Private Sub TestOnLoad()
Debug.WriteLine("ON LOAD Base Class")
End Sub
I then have a class which inherits from the base which takes a long
time to execute.
Private Sub MatterProfile_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Debug.WriteLine("BEFORE SLEEP SUB Class")
System.Threading.Thread.Sleep(5000)
Debug.WriteLine("After Seep SUB Class")
End Sub
Now, I am pretty sure that calling 'BeginInvoke' calls the delegate on
a ThreadPool thread. So, to my ignorant mind, I would expect my
output window to show something like this, with a possible race
condition flip flopping the middle two statements.
BASE CLASS LOAD
BEFORE SLEEP SUB Class
ON LOAD Base Class
AfterSleep SUB Class
In fact what always happens is that I see the following:
BASE CLASS LOAD
BEFORE SLEEP SUB Class
AfterSleep SUB Class
ON LOAD Base Class
So, it looks to me like there's an execution stack (or something) that
has the base Load event and the subclass Load event already stacked up
and the ThreadPool cannot start executing the TestOnLoad method until
the other two functions are executed off of the stack.
Can one of you bright people out there explain what's happening here?
I trust my results, but I'd MUCH rather understand the 'why'.
Thanks!
predictable.
Let's say I have a base class user control with a 'Load' event handler
and a sub:
Private Sub iMatterControlForm_Load(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Me.Load
Debug.WriteLine("BASE CLASS LOAD")
Me.BeginInvoke(New MethodInvoker(AddressOf TestOnLoad))
End Sub
Private Sub TestOnLoad()
Debug.WriteLine("ON LOAD Base Class")
End Sub
I then have a class which inherits from the base which takes a long
time to execute.
Private Sub MatterProfile_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Debug.WriteLine("BEFORE SLEEP SUB Class")
System.Threading.Thread.Sleep(5000)
Debug.WriteLine("After Seep SUB Class")
End Sub
Now, I am pretty sure that calling 'BeginInvoke' calls the delegate on
a ThreadPool thread. So, to my ignorant mind, I would expect my
output window to show something like this, with a possible race
condition flip flopping the middle two statements.
BASE CLASS LOAD
BEFORE SLEEP SUB Class
ON LOAD Base Class
AfterSleep SUB Class
In fact what always happens is that I see the following:
BASE CLASS LOAD
BEFORE SLEEP SUB Class
AfterSleep SUB Class
ON LOAD Base Class
So, it looks to me like there's an execution stack (or something) that
has the base Load event and the subclass Load event already stacked up
and the ThreadPool cannot start executing the TestOnLoad method until
the other two functions are executed off of the stack.
Can one of you bright people out there explain what's happening here?
I trust my results, but I'd MUCH rather understand the 'why'.
Thanks!