Navigation

Search

Categories

On this page

Archive

Blogroll

Disclaimer
None - these are my opinions and they're also my employer's!

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 14
This Year: 0
This Month: 0
This Week: 0
Comments: 15

Sign In

 Saturday, April 21, 2007
Saturday, April 21, 2007 9:10:14 PM (Mountain Daylight Time, UTC-06:00) ( )
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:
 
   [Serializable]
   public class RemoteEventShim<T> : MarshalByRefObject where T : EventArgs, new()
   {
      public override object InitializeLifetimeService()
      {
         return null;
      }
 
      public event EventHandler<T> RemoteEvent;
 
      public void RemoteEventHandler(object sender, T e)
      {
         EventHandler<T> handler = RemoteEvent;
         if (handler != null)
         {
            handler(sender, e);
         }
      }
   }
Comments [0] | | # 
Comments are closed.