Convenient stand-in for the thread-safe delegate invocation idiom.
For example, instead of invoking a Click event handler in a thread-safe manner by writing:
EventHandler<EventArgs> threadSafeDelegateCopy = Click; if(null != threadSafeDelegateCopy) { threadSafeDelegateCopy(this, EventArgs.Empty); }
It can be invoked equivalently, but more simply using the DelegateCaller as:
DelegateCaller.Call(Click, this, EventArgs.Empty);
Public Member Functions |
|
DelegateCaller (Delegate d) | |
Construct a
DelegateCaller to call the given Delegate d. |
|
object | Call (Object[] args) |
Calls the encapsulated delegate (possibly a
multicast delegate) and returns the object returned by the
delegate. |
|
Static Public Member Functions |
|
static object | Call (Delegate d, params Object[] args) |
Call the given delegate or event with the
given arguments. |
|
Properties |
|
bool |
Callable [get] |
Is the encapsulated delegate valid and
callable? |
CSharpUtilities::DelegateCaller::DelegateCaller | ( | Delegate | d | ) | [inline] |
Construct a DelegateCaller to call the given Delegate d.
d | The delegate to safely call. |
object CSharpUtilities::DelegateCaller::Call | ( | Object[] | args | ) | [inline] |
Calls the encapsulated delegate (possibly a multicast delegate) and returns the object returned by the delegate.
Traps any thrown exception.
args | Arguments passed to the delegate |
static object CSharpUtilities::DelegateCaller::Call | ( | Delegate | d, |
params Object[] | args | ||
) | [inline, static] |
Call the given delegate or event with the given arguments.
d | The delegate to call. |
args | The C# params modifier is roughly equivalent to the C++ ellipsis (...). It will build the args parameter array from the caller site parameter list. In this case, the arguments must be of the type and in the order expected by the delegate. |
bool CSharpUtilities::DelegateCaller::Callable
[get] |
Is the encapsulated delegate valid and callable?