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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:18:07+00:00 2026-05-13T17:18:07+00:00

I am using a plugin system on an ASP.NET MVC application I am working

  • 0

I am using a plugin system on an ASP.NET MVC application I am working on (loosely based on Rob Connery’s MVC storefront project implementation).

In addition to executing plugin methods, I also want to allow classes to provide various event hooks that a plugin can subscribe to.

I am publishing my events like so:

        #region Events

    public static event ItemAddedEventHandler ItemAdded;
    internal virtual void OnItemAdded(EventArgs e)
    {
        if (ItemAdded != null)
            ItemAdded(this, new EventArgs());
    }

    public static event LineRemovedEventHandler LineRemoved;
    internal virtual void OnLineRemoved(EventArgs e)
    {
        if (LineRemoved != null)
            LineRemoved(this, new EventArgs());
    }

    #endregion

    public delegate void ItemAddedEventHandler(object sender, EventArgs e);
    public delegate void LineRemovedEventHandler(object sender, EventArgs e);

And an example plugin:

        public EventHooks() {
        Cart.ItemAdded += new Cart.ItemAddedEventHandler(Cart_ItemAdded);
        Cart.LineRemoved += new Cart.LineRemovedEventHandler(Cart_LineRemoved);
    }

    void Cart_ItemAdded(object sender, EventArgs e) {
        _loggerService.Info("An item was added to the cart.");
    }

    void Cart_LineRemoved(object sender, EventArgs e) {
        _loggerService.Info("A line was removed from the cart.");
    }

Is this a good and thread safe way of publishing and subscribing to these events?

Any thoughts or suggestions appreciated.

Thanks
Ben

  • 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-13T17:18:07+00:00Added an answer on May 13, 2026 at 5:18 pm

    Assign your EventHandler’s to a local var before firing them.

    ItemAddedEventHandler handler = ItemAdded;
    
    if (handler != null) 
    {
       handler(this, EventArgs.Empty) 
    }
    

    There is a race condition between checking the null and firing the event. You’d better follow the guidelines anyhow.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A solution would be to use a combination of end… May 13, 2026 at 8:49 pm
  • Editorial Team
    Editorial Team added an answer have you tried setting the gv properties first and then… May 13, 2026 at 8:49 pm
  • Editorial Team
    Editorial Team added an answer Try using the COALESCE function to force a value when… May 13, 2026 at 8:49 pm

Related Questions

I am wondering what your thoughts are on maintaining relationship constraints within a MS
Background Info I am working on setting up a method for my company's developers
I have a shared runtime package that I am using to support an application
I'm using dlopen() in an Apache module that I am writing so that I
I'm trying to write an extension (plug-in) for Eclipse BIRT reporting. It involves extracting

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.