Frage

I am trying to come up with a way to raise a public event that can be seen by more than one application. The first thing that comes to mind is SystemEvents.

Is there a way to "define" a new SystemEvent or even a public event that more than one application can see and listen for.

War es hilfreich?

Lösung

Do you really need to use SystemEvent? How about other methods for IPC

IpcChannel is an alternative technique that seems to fit your requirements.

Andere Tipps

I don't think there is an easy .Net built in way to do this. The only way I know of is to use PostMessage or SendMessage to the Windows Event Queue. You can read the details About Messages and Message Queues. There are TONS of resources for invoking these native commands on google, but one of the best to start with is pinvoke.net.

The underlying plumbing for SystemEvents are Windows messages that are broadcast to all top level windows. Messages like WM_SETTINGCHANGED. You too can broadcast messages, pinvoke SendMessageTimeout with HWND_BROADCAST. This is somewhat risky, you'll be sending messages to programs that have never seen the message number before. At the very least you'll need to use RegisterWindowMessage() to ensure you get a unique message number that's known to you and to the processes that you want to be aware of the notification and don't confuzzle the rest of them.

There are more reliable mechanisms with less risk, a named pipe server for example.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top