Event pattern question RRS feed

  • Question

  • Hi

    I'm sure everyone has noticed how the concept of an event in .Net is different to the same concept inside the OS.

    In the OS threads, even processes, can communicate by signalling, waiting for and responding to events. But in the managed world an event is really just a callback. The thread that executes an event handler is always the same thread that causes the event to be 'notified'.

    So is there a managed way for me to have a handler in some app domain get run when another app domain 'triggers' an event?

    Is there any class library support for this?

    I'd like to have some method in my class automatically get executed when some other process notifies some 'event'.

    In essence I'd like to call some method:

    SetEventHandler (<some win32 event>,<some handler method>);

    so that when some other thread/process notifies the win32 event, the specified handler in my process gets run.

    Does this make sense?

    Is there some support already?

    Am I missing some other .Net support that can do a similar thing?

    Tuesday, November 4, 2008 2:15 PM


All replies

  • Most of the OS-level wait-handles can be used with "global" names, allowing them to be used for IPC.

    MSDN has a sample of OpenExisting here:

    You'd need some code waiting for the event, but that's about it...

    I believe you need the "global\" prefix on the name for it to be usable for your needs.

    Marc [C# MVP]
    Tuesday, November 4, 2008 3:45 PM
  • Hi Mark

    Yes, I am aware of the potential to do as you suggest.

    What I am really asking is this:

    Is there a way with .Net to have a handler in some thread in app A get executed when some thread in app B activates it?

    The SetEventHandler pseudo-example was trying to convey this.

    What I am designing is a publish/subscribe infrastructure in which a 'server' process, dedicated to thi task, performs central work on data and then decides which 'client' apps need to be told.

    There are numerous ways to do this of course, 'client' threads can simply do some sort of blocking /wait for example, but I am just wondering if there is a way that 'looks like' an event type, handler type of setup.






    Thursday, November 6, 2008 8:08 AM