Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8345057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:33:57+00:00 2026-06-09T06:33:57+00:00

I have a base class, a middle class that inherits from the base, and

  • 0

I have a base class, a middle class that inherits from the base, and a top class that inherits from the middle class. I defined an event in the base class and raise it from a method. I defined a handler in the middle class for the base class event, and also the same handler in the top class.
When the event fires, the middle class handler gets hit first, then the top class handler.

If I keep adding more classes to the chain (ultra inherits from top, supreme inherits from ultra, etc.), the event handlers keep getting called in the most basic classes first (e.g., middle, top, ultra, supreme).

Does this sequence always hold?
If not, what could / would make it go in a different order?

The order I’m observing suits this function perfectly; I just want to make sure it will work consistently.

I understand events are not guaranteed to fire in any order, BUT this is something the framework knows about at compile time, and as the author of the code I can say there will be no adding / removing of delegates at runtime for this event, nor will the event be consumed outside the base and it’s subclass chain; in fact, it’s protected.

I don’t know what happens behind the scenes, but maybe it sets the sequence during compile and therefore at run-time it’s a done deal?

EDIT: I’m adding the sample for clarity of what I’m doing.

Public Class BaseClass

  Protected Event Hello(ByRef Cancel As Boolean)

  Public Sub SayHello()
    Dim Cancel As Boolean
    RaiseEvent Hello(Cancel)
  End Sub

End Class

Public Class MiddleClass
  Inherits BaseClass

  Private Sub MiddleClass_Hello(ByRef Cancel As Boolean) Handles Me.Hello
    'This appears to always get called first
  End Sub

End Class

Public Class TopClass
  Inherits MiddleClass

  Private Sub TopClass_Hello(ByRef Cancel As Boolean) Handles Me.Hello
    'This appears to always get called second
  End Sub

End Class

Public Class UltraClass
  Inherits TopClass

  Private Sub UltraClass_Hello(ByRef Cancel As Boolean) Handles Me.Hello
    'This appears to always get called third
  End Sub

End Class

'...and so on
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:33:58+00:00Added an answer on June 9, 2026 at 6:33 am

    In your particular code sample, the order will behave how you expect.

    When you have a method that’s marked as Handles Me...., all the VB compiler does is stick a hidden AddHandler statement at the very beginning of your constructor. Constructors run from the base type to derived type, and so the hidden AddHandler for the base types will run before the AddHandler in the derived types. As long as your RaiseEvent were to raise events in the order the handlers were added, then yes, you’ll see the order you see now. For simple VB events like you have, that behavior is highly unlikely to change.

    Observe my caveat above: if the event was not a simple event but rather a Custom Event where the base class can specify it’s own behavior for AddHandler and RaiseEvent, all bets are off. Nothing would prevent me from making my own RaiseEvent that runs handlers in any random order I want (assuming it even runs them all!) If the Base class isn’t something you own, I would be careful if you assume ordering.

    In general, event handlers that have subtle ordering requirements can often create hard-to-debug bits of code. It’s best avoided if you can. If the base/derived ordering is important, you might be able to make the code clearer by using overridden methods and have derived types call MyBase in the appropriate place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class, defined as below (I'm also using DevExpress components): public
Say I have base class A. it has method void foo(A* a); It also
I have a base class ( car ) and a class that inherit the
I have a base class that looks like the following: template<typename T> class Base
I have a base class that is a Django form. The child class then
So let's say I have two classes that inherit a base class that has
I have a base class called BaseEvent . And, 3 classes derived from BaseEvent
I have a base class, Primitive , from which I derive several other classes--
I have a base class that has methods that use a generic type in
I have a base class and a a second class that's extends the base

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.