I am building a simple class to hold related methods. Part of this code includes synchronising to a database. The built in SyncOrchestrator class includes a SessionProgress event handler which I can wire up an event to.
What I would like to do is instance my class and then hook up an some code to this event so that I can display a progress bar (ill be using BGWorker).
So, my question is probably c# 101, but how do I expose this event through my class the correct way so that I can wire it up?
Thanks
I think you’re looking for something like this:
(I also suggest you read the Events tutorial on MSDN.)
where the
MyEventArgstype is derived from theEventArgsbase type and contains your progress information.You raise the event from within the class by calling
OnSessionProgress(...).Register your event handler in any consumer class by doing:
Similarly, use
-=to unregister the event; often not explicitly required.