Tutorial
This tutorial gives you a quick look at how to use the EventBroker in simple scenarios. Check out the rest of the documention for a full list of features.
Sample publisher
Publish an event topic:
Register the publisher with your event broker (you have to hold an instance of the event broker somewhere in your code).
On registration of the publisher, the event broker inspects the publisher for published events
(events with the EventPublication
attribute).
Sample subscriber
Subscribe to an event topic:
Register the subscriber with the event broker:
The event broker will inspect the subscriber on registration for subscription to event topics
(methods with the EventSubscription
attribute).
If a publisher fires an event topic for that subscribers are registered, then the event broker will relay them to the subscribers
by calling the subscription handler methods with the sender
and EventArgs
the publisher used to fire its event.
Publication options
Simple
With custom Eventargs
Note: CustomEventArgs
has simply to be derived from EventArgs
.
Publish multiple event topics with one single event
Allow only synchronous subscription handlers
Allow only asynchronous subscription handlers
Subscription options
Simple
Custom EventArgs
Subscribe multiple event topics
Execute handler on background thread (asynchronous)
The event broker creates a worker thread to execute the handler method on. The publisher can immediately continue processing.
Execute handler on UI thread
Use this option if calling from a background worker thread to a user interface component that updates the user interface - no need for Control.Invoke(...) anymore.
Note that if you use the OnUserInterface
handler, you have to make sure that you register the subscriber on the user interface thread.
Otherwise, the EventBroker won't be able to switch to the user interface thread, and will throw an exception.
Execute handler on UI thread asynchronously
The same as above, but the publisher is not blocked until the subscriber has processed the event.
Simplified subscription handler signatures
If you are not interested in the sender of the event, you can leave the sender out in the handler method:
If you also don't need the event arguments, you can ignore them, too:
And if you have a generic event argument EventArgs<T>
, you can directly define the content value of the event arguments:
These are the basics about the EventBroker. See the rest of the documentation for more options and details.