Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to signal an event to several processes in .NET

Tags:

c#

.net

events

I was hoping there was an easy way to signal an event to several processes that did not involve me writing a custom socket listener. I'm trying to inform several applications that will need to update their cached configuration settings that a config change has occurred. I wanted to implement a "host wide" singleton, but have failed to find any examples. Is such a thing even possible?

like image 437
feihtthief Avatar asked Sep 30 '09 17:09

feihtthief


2 Answers

You can use a named EventWaitHandle. However, you'd also need some way to reset the event after all of the processes listening were notified. You can probably do something like set the event and then reset it after some short period of time: one second or five seconds. Clients could know that the event won't trigger that quickly in succession.

Another possibility is to use a named Semaphore. But then you need to know how many listeners there are so that you can set the Semaphore's initial and maximum values.

There are ways to do what you're asking without having to build anything fancy.

like image 169
Jim Mischel Avatar answered Nov 08 '22 22:11

Jim Mischel


Named semaphore and Named mutex are used for interprocess synchronization.

Msdn says:

Semaphores are of two types: local semaphores and named system semaphores. If you create a Semaphore object using a constructor that accepts a name, it is associated with an operating-system semaphore of that name. Named system semaphores are visible throughout the operating system, and can be used to synchronize the activities of processes.

Msdn says:

Named system mutexes are visible throughout the operating system, and can be used to synchronize the activities of processes. You can create a Mutex object that represents a named system mutex by using a constructor that accepts a name. The operating-system object can be created at the same time, or it can exist before the creation of the Mutex object.

Hope this helps

like image 36
grega g Avatar answered Nov 08 '22 23:11

grega g