What are the drawbacks of a delegate

Showing Answers 1 - 1 of 1 Answers

Pixelgrease

  • Oct 15th, 2006
 

When invoking multicast delegates, if any of the implementing methods throws an exception, it will prohibit the pending methods from invocation.

A way around this is to explicitly iterate the delegates and invoke them inside a try-catch block. The code might look like this:

// Instead of : myhandler(null, EventArgs.Empty);

foreach
(MyDelegate md in
myhandler.GetInvocationList())
{
    try
   
{
        md(null, EventArgs.Empty));
    }
   
catch
   
{ } // methods that throw exceptions are ignored
}

 

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions