
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
490
|
Chapter 9: Delegates, Events, and Anonymous Methods
Console.WriteLine("Invoked Method2");
return (false);
}
public static bool Method3( )
{
Console.WriteLine("Invoked Method3");
return (true);
}
}
Discussion
A delegate, when called, will invoke all delegates stored within its invocation list.
These delegates are usually invoked sequentially from the first to the last one added.
With the use of the
GetInvocationList method of the MulticastDelegate class, you
can obtain each delegate in the invocation list of a multicast delegate. This method
accepts no parameters and returns an array of
Delegate objects that corresponds to
the invocation list of the delegate on which this method was called. The returned
Delegate array contains the delegates of the invocation list in the order in which they
would normally be called; that is, the zeroth element in the
Delegate array contains
the
Delegate object that is normally called first.
This application of the
GetInvocationList method gives you the ability to control
exactly when and how the delegates in a multicast delegate are invoked and allows
you to prevent the continued invocation of delegates when one delegate fails. This
ability is important if each delegate is manipulating data and one of the delegates
fails in its duties but does not throw ...