I built a Windows service to host different processors that work with MSMQ. Each processor is running in its own AppDomain and needs to fire events to the host service. .NET remoting is used to wire up the connections between the host process and the processors as a result of the cross appdomain communication requirement.
Handling events in this scenario requires a handler or shim to be used to avoid requiring a reference to the event subscriber in the event publisher. The shim is simply a broker or proxy for both sides. I tried to find an example of one that used generics but was unable to so I decided to come up with one. It's essentially wrapping the built-in generic EventHandler<T>. This allows any event argument type to be passed as T.
Here's the code:
public class RemoteEventShim<T> : MarshalByRefObject where T : EventArgs, new()
public override object InitializeLifetimeService()
public event EventHandler<T> RemoteEvent;
public void RemoteEventHandler(object sender, T e)
EventHandler<T> handler = RemoteEvent;