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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:56:23+00:00 2026-05-22T15:56:23+00:00

What speaks against using the delegates System.Action or System.Func as EventDelegates instead of the

  • 0

What speaks against using the delegates System.Action or System.Func as EventDelegates instead of the classic EventHandler pattern. Will I therefore run into problems?

private bool disposed;

public event Action<IUnitOfWork, IContext> Disposing;

public void Dispose()
{
    if (this.disposed)
    {
        return;
    }

    if (null != this.Disposing)
    {
        this.Disposing(this, this.AttachedContext);
    }

    this.disposed = true;
}

Usage:

unitOfWorkInstance.Disposing += (u, c) => c.Rollback(u); // in my opinion more readable than
unitOfWorkInstance.Disposing += (sender, args) => args.AttachedContext.Rollback(sender as IUnitOfWork);
  • 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-22T15:56:24+00:00Added an answer on May 22, 2026 at 3:56 pm

    Well, the code you’ve given there isn’t thread-safe – someone could unsubscribe from the eventhandler after your nullity test and before your call this.Disposing.

    But in general, it should work just fine. The downside is that by not following the EventHandler convention, you’re slightly more limited in terms of what can subscribe.

    For example, suppose you have a very general event handler method:

    public void LogEvent(object sender, EventArgs e)
    {
        Console.WriteLine("Event raised");
    }
    

    You can use this to subscribe to any event following the normal convention – but not with
    your event.

    This is a pretty minor downside though. I guess a potentially bigger one is that it may confuse other developers who are expecting to see a conventional event signature.

    EDIT: I’ve just remembered that some other libraries may expect the conventional event signature – Reactive Extensions does, for example. IIRC, it’s not impossible to subscribe to other events, just a bit harder.

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

Sidebar

Related Questions

I'm doing a project with a 3D model, that speaks. So, I'm using SAPI
I am writing a count down timer, using .postdelayed(), that speaks each second as
I am using the Emacs-Speaks-Statistics (ESS) mode for Emacs. When editing R code, any
I am a fairly new user of R and have started using Emacs Speaks
I have an application that speaks to a server on a regular basis using
The title speaks for itself... I've tried to find another question like it but
The title speaks for itself .... Does choice of container affects the speed of
The title speaks for itself. I'm building a winforms C# 2.0 app. Any tutorials
ess-mode is Emacs speaks statistics. This mode is useful for editing programs for R
I have this simple code that speaks for itself. <script language='javascript"> function check() {}

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.