By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 1,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

Rasied Events traverse the call stack until handled

P: n/a
Using vs 2003, vb.net

It is not clear from the documentation, but it appears that a raised event
will traverse up the call stack upwards until it reaches its handler. Is
this correct? See the code snippet below. The event raised in sub1 or
class three will be caught in Class1 event handler (I know below is not
syntactically correct, but you get the idea).
Class 1 '------------------
friend Class2 as Class2x
Sub TestEvent_EventHandler Handles TestEvent
' raised event in class 3 caught here
end sub

' call something in class 2

end class

Class2 '------------------

friend Class3 as class 3x

Call Sub1 in class3

end class

Class 3 '------------------

Event TestEvent

Sub 1

RaiseEvent TestEvent

end sub

End class

please advise.

Bob Day


Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Bob,

Thanks for using Microsoft MSDN Managed Newsgroup. My name is Gary, and I
will be assisting you on this issue.

Currently I am looking for somebody who could help you on it. We will reply
here with more information as soon as possible.
If you have any more concerns on it, please feel free to post here.
Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 20 '05 #2

P: n/a
It is not clear from the documentation, but it appears that a raised event
will traverse up the call stack upwards until it reaches its handler. Is
this correct?


No, when you raise an event you just en up calling the list of handler
methods sequentially. There's no stack walking going on.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #3

P: n/a
Whats the practical difference? If the handler is 3 levels up from where
the event was raise, it will be caught 3 levels up from where the event was
raised. Is this not the same as traversing the call stack up?

On a related mater, if multiple threads call the instantiated class that may
raise the same event, and all threads have the same handlers 3 levels up,
only the handler that will be trigger is the one that instantiated the
class, correct? Certainly handlers in other classes or threads would not be
triggered. I think the answer is yes - it would follow the stack back up to
its handler, even if there were identical handlers in other classes..

Your thoughts.

Thanks!

Bob Day

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:O5**************@TK2MSFTNGP10.phx.gbl...
It is not clear from the documentation, but it appears that a raised eventwill traverse up the call stack upwards until it reaches its handler. Is
this correct?


No, when you raise an event you just en up calling the list of handler
methods sequentially. There's no stack walking going on.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 20 '05 #4

P: n/a
Bob,
Are you confusing RaiseEvent with Throw exception?

As Mattias stated RaiseEvent does NOT tranverse stack frames, it calls each
handler added to the Event with AddHandler or Handles in turn, then returns
you to the current stack frame.

Throw exception will traverse up the call stack until a Catch block is
found.

From you description it sounds like you are talking Throw exception, while
your sample is (attempting) to show RaiseEvent.

Hope this helps
Jay

"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Using vs 2003, vb.net

It is not clear from the documentation, but it appears that a raised event
will traverse up the call stack upwards until it reaches its handler. Is
this correct? See the code snippet below. The event raised in sub1 or
class three will be caught in Class1 event handler (I know below is not
syntactically correct, but you get the idea).
Class 1 '------------------
friend Class2 as Class2x
Sub TestEvent_EventHandler Handles TestEvent
' raised event in class 3 caught here
end sub

' call something in class 2

end class

Class2 '------------------

friend Class3 as class 3x

Call Sub1 in class3

end class

Class 3 '------------------

Event TestEvent

Sub 1

RaiseEvent TestEvent

end sub

End class

please advise.

Bob Day

Nov 20 '05 #5

P: n/a
Thanks, that was very helpful.

Bob Day

"Bob Day" <Bo****@TouchTalk.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Using vs 2003, vb.net

It is not clear from the documentation, but it appears that a raised event
will traverse up the call stack upwards until it reaches its handler. Is
this correct? See the code snippet below. The event raised in sub1 or
class three will be caught in Class1 event handler (I know below is not
syntactically correct, but you get the idea).
Class 1 '------------------
friend Class2 as Class2x
Sub TestEvent_EventHandler Handles TestEvent
' raised event in class 3 caught here
end sub

' call something in class 2

end class

Class2 '------------------

friend Class3 as class 3x

Call Sub1 in class3

end class

Class 3 '------------------

Event TestEvent

Sub 1

RaiseEvent TestEvent

end sub

End class

please advise.

Bob Day

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.