
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
496
|
Chapter 9: Delegates, Events, and Anonymous Methods
invoked. One way to deal with this is to store all of the exceptions that occur during
delegate processing, then wrap all of the exceptions encountered during processing
in a custom exception. After processing completes, throw the custom exception. See
the
MyExceptionHoldingException class in the Solution.
By adding a
finally block to this try-catch block, you can be assured that code
within this
finally block is executed after every delegate returns. This technique is
useful if you want to interleave code between calls to delegates, such as code to clean
up objects that are not needed or code to verify that each delegate left the data it
touched in a stable state.
See Also
See Recipes 9.1 and 9.2; see the “Delegate Class” and “Delegate.GetInvocationList
Method” topics in the MSDN documentation.
9.4 Converting Delegate Invocation from
Synchronous to Asynchronous
Problem
You have determined that one or more delegates invoked synchronously within your
application are taking a long time to execute. This delay is making the user interface
less responsive to the user. The invocation of these delegates should be converted
from synchronous to asynchronous mode.
Solution
A typical synchronous delegate type and supporting code that invokes the