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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:57:26+00:00 2026-05-11T01:57:26+00:00

I have come across what must be a common problem. When I have an

  • 0

I have come across what must be a common problem. When I have an event which may be subscribed to by several different classes, an exception thrown by one of these classes will kill the callback chain; as I do not know a priori in what order the callback is carried out, this can result in unpredictable state changes for some classes and not for others.

In the bible (CLR via C#, I am using C# 2.0) there is a short paragraph about using MulticastDelegate.GetInvocationList to get around this, but nothing more. So my question is: what is the best way to deal with this? Do I have to use MulticastDelegate.GetInvocationList every time I have an event?? Or do I need to enclose all methods which may be called as part of the delegate chain in some kind of rollback mechanism? Why are all these options so complicated in comparison to the simple event/delegate model which is so easy to use in C#? And how can I use the simple way without ending up with corrupted state?

Thanks!

  • 1 1 Answer
  • 3 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-11T01:57:27+00:00Added an answer on May 11, 2026 at 1:57 am

    If you simply invoke a delegate, it will call all the target methods in order. You need to use GetInvocationList if you want to execute them individually – for example:

    • to check Cancel after each
    • to capture the return value of each
    • to continue after failure of an individual target

    As for the best way to use it: how do you want it to behave? It isn’t clear to me… for example, this might suit an extension method quite well:

    static void InvokeIgnoreErrors(this EventHandler handler,         object sender) {     if(handler != null) {         foreach(EventHandler subHandler in handler.GetInvocationList()) {             subHandler(sender, EventArgs.Empty);         }     } } 

    Then you can just call myHandler.InvokeIgnoreErrors(this); (for example).

    Another example might be:

    static bool InvokeCheckCancel(this CancelEventHandler handler,         object sender) {     if(handler != null) {         CancelEventArgs args = new CancelEventArgs(false);         foreach(CancelEventHandler subHandler in handler.GetInvocationList()) {             subHandler(sender, args);             if(args.Cancel) return true;         }     }     return false; } 

    which stops after the first event requests cancellation.

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

Sidebar

Related Questions

I have come across a situation (which I think is weird but is possibly
I have come across an annoying problem while writing some PHP4 code. I renamed
I've come across a really strange problem. I have written a simple Deck class
I'm trying to learn dependency injection and have come across a problem, when unit
I have come across a very odd problem in C that I have never
We have come across a scenario where we need to track the setting and
I have come across a very weird error. I'm on Solaris 10, using Ruby
I have come across some strange behaviour, and I'm assuming a bug in Firefox,
I have come across Evernote's bookmarklet and was wondering how this worked. You can
I have come across this great function/command . Colour to RGB, you can do

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.