Hi:
I was curious whether events fired as a multi-cast delegate were fired
asynchronously or not.
How are you raising the event? If you use the standard language mechanisms
then they are synchronous:
public event MyDelegate OnTest;
void Test()
{
// do something
OnTest();
}
This means that however many delegates are added to the event OnTest they
will all be invoked one after another on the same thread. You can access the
invocation list and invoke the delegates on another thread if you wish.
If the invoked delegate is OneWay,
[OneWay] means that *no* return values of any type will be returned from the
delegate, not even exceptions. Although it is useful for async calls, its
not required.
do I need
to call GetInvocationList() (I think that's the name) and fire each
one asynchronously to take advantage of the OneWay delegate, or will
firing the event with one call do that for me?
No. If you have multiple delegates in an event (or in a multicast delegate
for that matter), then any out parameters and return values are irrelevent.
The only return values will be returned from the *last* delegate invoked.
Hence in general delegates that are called through a multicast delegate
should not have any return values unless you make a special effort to call
each delegate separately (through the invocation list). Thus [OneWay]
actually makes *more* sense on a multicast delegate when you use the default
invocation mechanism. Note that the attribute prevents exception
propagation, which is useful if you write a component and a third party
class calls your code: you don't know if their event handlers are written
correctly and by using [OneWay] you ensure that all event handlers are
called even if one throws an exception.
Richard