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

  • Home
  • SEARCH
  • 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 716863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:20:50+00:00 2026-05-14T05:20:50+00:00

I’m looking for some pointers on implementing Custom Events in VB.NET (Visual Studio 2008,

  • 0

I’m looking for some pointers on implementing Custom Events in VB.NET (Visual Studio 2008, .NET 3.5).

I know that “regular” (non-custom) Events are actually Delegates, so I was thinking of using Delegates when implementing a Custom Event. On the other hand, Andrew Troelsen‘s “Pro VB 2008 and the .NET 3.5 Platform” book uses Collection types in all his Custom Events examples, and Microsoft’s sample codes match that line of thought.

So my question is: what considerations should I have when choosing one design over the other? What are the pros and cons for each design? Which of these resembles the inner-implementation of “regular” events?

Below is a sample code demonstrating the two designs.

Public Class SomeClass
    Private _SomeEventListeners As EventHandler
    Public Custom Event SomeEvent As EventHandler
        AddHandler(ByVal value As EventHandler)
            _SomeEventListeners = [Delegate].Combine(_SomeEventListeners, value)
        End AddHandler

        RemoveHandler(ByVal value As EventHandler)
            _SomeEventListeners = [Delegate].Remove(_SomeEventListeners, value)
        End RemoveHandler

        RaiseEvent(ByVal sender As Object, ByVal e As System.EventArgs)
            _SomeEventListeners.Invoke(sender, e)
        End RaiseEvent
    End Event

    Private _OtherEventListeners As New List(Of EventHandler)
    Public Custom Event OtherEvent As EventHandler
        AddHandler(ByVal value As EventHandler)
            _OtherEventListeners.Add(value)
        End AddHandler

        RemoveHandler(ByVal value As EventHandler)
            _OtherEventListeners.Remove(value)
        End RemoveHandler

        RaiseEvent(ByVal sender As Object, ByVal e As System.EventArgs)
            For Each handler In _OtherEventListeners
                handler(sender, e)
            Next
        End RaiseEvent
    End Event
End Class
  • 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-05-14T05:20:50+00:00Added an answer on May 14, 2026 at 5:20 am

    I would say use the simple delegate; simply – it is already (internally) a list, so you are duplicating effort by wrapping it in List<T>. You also have the overhead of extra list objects and arrays, that could be null, so more impact on garbage collection etc.

    Also, if you are doing lots of this, consider EventHandlerList, which exists to provide efficient access to sparse events – i.e. where you want to expose lots of events but many of them can be unassigned.

    The first example is far closer to “standard” events (although you might want to watch for unassigned / null handlers when calling Invoke, as it could be null). Additionally, note that some languages (I honestly don’t know what VB does here) applies synchronization to events, but in reality very few events really need to be thread-safe, so that could be overkill.

    edit it also occurs that there is a functional difference between them:

    • the delegate approach treats different instances with the same target method / instance as equal (I don’t think the List<T> will)
    • duplicate delegates: delegate removes last first; list removes earliest first
    • composites: add A, add B, and remove (A+B) – with a delegate this should yield null / empty, but the list approach will retain A and B (with the (A+B) remove failing to find anything)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I got it! Apparently RewriteCond needs the whole directory structure… May 14, 2026 at 8:17 pm
  • Editorial Team
    Editorial Team added an answer I believe that the full-trust option is only available as… May 14, 2026 at 8:17 pm
  • Editorial Team
    Editorial Team added an answer The regular expression you need is: X[-\d.]+Y[-\d.]+ Here is how… May 14, 2026 at 8:17 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.