|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionI recently started using Marc Clifton's excellent EventPool component to simplify the use of creating and using events. As Marc indicates in his writeup on the component, there are some drawbacks relating to the use of BackgroundWith the advent of .NET 2 and the introduction of generics, it seemed the ideal opportunity to revisit the
Here we go through the different ways of using the Derived Event ArgumentsSuppose that you want to subscribe to an event handler which uses an event argument class called eventPoolHandler.EventPool.Subscribe
("Add", new EventHandler<AddEventArgs>(AddEventHandler));
Then, code up your event handler as you would normally: private void AddEventHandler(object sender, AddEventArgs aea)
{
// Do something.
}
To actually raise the event, you call: eventPool.Fire("Add", this, new AddEventArgs());
You now have typesafe event arguments. Enumerated EventsOne of the problems with using There are two ways to hook your enumerations up as events. One method allows you to pick a specific enumeration and publish that one only, the other allows you to publish all elements in the enumeration. When you subscribe to an enumeration or fire it, you must pick the specific enumeration. Samplepublic enum FileOperations
{
Opening,
Closing,
Saving
}
public class EventPublisher : IEventPool
{
private EventPool eventPool;
public EventPublisher()
{
this.eventPool = new EventPool();
this.eventPool.Publish(typeof(FileOperations));
}
public EventPool EventPool
{
get { return this.eventPool ; }
}
}
Unsubscribe From An EventSometimes you want to unsubscribe from event notifications. In this case, you simply call the eventPoolHandler.EventPool.Unsubscribe
(FileOperations.Opening, new EventHandler<AddEventArgs>(AddEventHandler));
Supported Events and Unsubscribed EventsThe The Publishing Events using AttributesIn the assembly, there is an public enum FileOperations
{
Opening,
Closing,
Saving,
}
[EventPool(typeof(FileOperations))]
public class EventPublisher : IEventPool
{
private EventPool eventPool = new EventPool();
public EventPublisher() {}
public EventPool EventPool
{
get { return eventPool ; }
}
}
FinallyI hope that this gives you some taste of what you can do with the History
|
||||||||||||||||||||||