Search code examples
c#eventsassembliessolution

how do I subscribe to an event in raised in another assembly


I have a solution which contains 3 project. One project handles asynchronous communinications. When it has completed it's callback, it raises an event SomethingCompleted. How do I subscribe to this event from another project in the same solution?

I have the event handlers built in the receiving project but it does not see the event in the sending project.


Solution

  • You need to have a reference to the class raising the event to register an event handler.

    Once you have that, it's done like registering any other event handler:

    foo.SomethingCompleted += (sender, e) => this.DoSomething();