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 160317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:00:49+00:00 2026-05-11T11:00:49+00:00

I’m developing a class library to be used for other developers and will be

  • 0

I’m developing a class library to be used for other developers and will be allowing them to either declare an instance of my class using WithEvents (or similar in other languages) as well as allow them to use Delegates defined in the class. Am I just being redundant here by doing it like this?

Public Delegate Sub TimerElapsedDelegate(ByVal sender As Object, ByVal e As System.EventArgs) Public Event TimerElapsed(ByVal sender As Object, ByVal e As System.EventArgs) Private _TimerElapsed As TimerElapsedDelegate = Nothing 

Or should I just declare the events and let them do the AddHandler, etc., ?

Thanks for any advice on this … I think I’m being redundant and don’t want pointless code, not to mention avoiding the DRY principle.

{edit}Just wanted to post the remainder of the code, and stress that the ‘work’ an instance of this class performs is done on a separate thread.{/edit}

#Region 'Delegates' Public Delegate Sub TimerElapsedDelegate(ByVal sender As Object, ByVal e As System.EventArgs) Public Event TimerElapsed(ByVal sender As Object, ByVal e As System.EventArgs) Private _TimerElapsed As TimerElapsedDelegate = Nothing Public Property OnTimerElapsed() As TimerElapsedDelegate     Get         Return _TimerElapsed     End Get     Set(ByVal value As TimerElapsedDelegate)         If value Is Nothing Then             _TimerElapsed = Nothing         Else             If _TimerElapsed Is Nothing Then                 _TimerElapsed = value             Else                 _TimerElapsed = System.Delegate.Combine(_TimerElapsed, value)             End If         End If     End Set End Property Private Sub TriggerTimerElapsed()     If OnTimerElapsed IsNot Nothing Then         OnTimerElapsed.Invoke(Me, New System.EventArgs)     End If     RaiseEvent TimerElapsed(Me, New System.EventArgs) End Sub  Public Delegate Sub ItemReadyForQueueDelegate(ByVal sender As Object, ByVal e As System.EventArgs) Public Event ItemReadyForQueue(ByVal sender As Object, ByVal e As System.EventArgs) Private _ItemReadyForQueue As ItemReadyForQueueDelegate = Nothing Public Property OnItemReadyForQueue() As ItemReadyForQueueDelegate     Get         Return _ItemReadyForQueue     End Get     Set(ByVal value As ItemReadyForQueueDelegate)         If value Is Nothing Then             _ItemReadyForQueue = Nothing         Else             If _ItemReadyForQueue Is Nothing Then                 _ItemReadyForQueue = value             Else                 _ItemReadyForQueue = System.Delegate.Combine(_ItemReadyForQueue, value)             End If         End If     End Set End Property Private Sub TriggerItemReadyForQueue(ByVal oItem As h3Budgeteer.FileSystem.ReportTemplateFile.ReportTemplate)     If OnItemReadyForQueue IsNot Nothing Then         OnItemReadyForQueue.Invoke(Me, New ItemReadyForQueueEventArgs(oItem))     End If     RaiseEvent ItemReadyForQueue(Me, New ItemReadyForQueueEventArgs(oItem)) End Sub Public Class ItemReadyForQueueEventArgs     Inherits System.EventArgs     Private _ReportTemplate As h3Budgeteer.FileSystem.ReportTemplateFile.ReportTemplate = Nothing     Public ReadOnly Property ReportTemplate() As h3Budgeteer.FileSystem.ReportTemplateFile.ReportTemplate         Get             Return _ReportTemplate         End Get     End Property     Public Sub New(ByVal oReportTemplate As h3Budgeteer.FileSystem.ReportTemplateFile.ReportTemplate)         _ReportTemplate = oReportTemplate     End Sub End Class 

End Region

  • 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. 2026-05-11T11:00:49+00:00Added an answer on May 11, 2026 at 11:00 am

    I would say just completely remove your delegate entirely.

    Your delegate is doing exactly the same thing as the event. You are pretty much writing your own event plumbing instead of using the framework’s Event call. An Event is pretty much exactly what you’ve written, except that it’s easier to use, and also makes it easier to unsubscribe from the event.

    There is no advantage to providing both – The event does everything that your ‘delegate’ does, and is much more clear.

    (Previously:)

    If you’re developing this as a class library, I would suggest just making your class not be sealed, and following the more standard approach. The normal approach for allowing logic to be overridden or inserted into your code and allowing events would be to provide hooks for subclassing.

    Delegates could be used in a situation like this to allow the user to plug in their own logic. However, in many cases, having protected virtual functions makes this more clear, and much easier to accomplish.

    Events should be exactly that, an event that notifies the user of some ‘event’. These should be hooks where the user attaches their delegate.

    For example, instead of providing delegates and events, the base Windows Forms controls use a protected method (ie: OnMouseDown) and an event that’s triggered by default (MouseDown).

    This allows a user to subclass your class and override the logic (which is probably why you’d want delegates) as well as handle the event.

    The one place where I would provide delegates is in rare cases where your class or method REQUIRES logic to be added by a user. In this case, you can either provide an abstract base class, or have a delegate that is passed in for that logic. A good example of this is the .Where() method in LINQ. Where is useless without the predicate used for filtering, so passing in a delegate makes sense in this case. Note, though, that there is no event associated with this – it’s really there to provide a different function.

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

Sidebar

Ask A Question

Stats

  • Questions 160k
  • Answers 160k
  • 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 Did you specify it as PDO::PROPEL_ATTR_CACHE_PREPARES? It should be PropelPDO::PROPEL_ATTR_CACHE_PREPARES… May 12, 2026 at 11:38 am
  • Editorial Team
    Editorial Team added an answer Well, it turns out that google-breakpad is pretty nice after… May 12, 2026 at 11:38 am
  • Editorial Team
    Editorial Team added an answer PHP sessions can use cookies depending on how you configure… May 12, 2026 at 11:38 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.