event model question

  • Thread starter Thread starter Colin McGuire
  • Start date Start date
C

Colin McGuire

If I have a routine that handles event A of class B coded in VB.Net
like:

Private Sub handleEventA Handles B.eventA
Debug.WriteLine("eventA handler for class B")
End sub


and then I perform the following three steps

1. Debug.WriteLine("step 1")
2. B.Setsomething=4 'this raises event A in class B
3. Debug.WriteLine("step2")


The output window in my IDE would show the following:

step1
eventA handler for class B
step2

My question is is this guaranteed, is this how the event model works,
or put anotherway, are the events guaranteed to be raised
synchronously?


Thank you
Colin
 
Colin McGuire said:
If I have a routine that handles event A of class B coded in
VB.Net like:

Private Sub handleEventA Handles B.eventA
Debug.WriteLine("eventA handler for class B")
End sub


and then I perform the following three steps

1. Debug.WriteLine("step 1")
2. B.Setsomething=4 'this raises event A in class B
3. Debug.WriteLine("step2")


The output window in my IDE would show the following:

step1
eventA handler for class B
step2

My question is is this guaranteed, is this how the event model
works, or put anotherway, are the events guaranteed to be raised
synchronously?


Yes, events a raised synchronously, unless the documentation says something
else.
 
Colin,

To the best of my knowledge, events are handled on the same thread they have
been raised on. So, in a single-threaded application, events are handled
just in the same order they have been raised - since raising an event
actually leads to calling one or more delegates (i.e. callbacks) subscribed
to this event.

For multi-threaded applications, I suppose, the order is retained for each
of the threads.
So, in your example:
1. Debug.WriteLine("step 1")
2. B.Setsomething=4 'this raises event A in class B
3. Debug.WriteLine("step2")

You should always be getting the same output:

step1
eventA handler for class B
step2
 
Back
Top