Frage

I have two projects A and B. Where project A is a system tray application, and project B is the main application. When the user changes the settings from project B, project A needs to update itself. How can I notify project A with the changes that happen?

I have tried to use Global Events but this needs to create a new instance of app A in app B when it starts.

War es hilfreich?

Lösung

There are several options. One way is to create a named EventWaitHandle. When project B updates the settings, it sets the event. Project A has a thread that waits on that event. When it gets a notification, it updates from the settings and then resets the event. I have a simple example here: Send message from one running console app to another

That will work if project B stores the new settings somewhere where project A can read them. If you want to do it in memory (i.e. project B doesn't persist the settings), then you need to set up some type of communication between the the two processes. You can set up shared memory using a MemoryMappedFile, in which case you'll still need the event notification.

Or you could set up a Named Pipe with a server stream in project B and a client stream in project A.

Andere Tipps

You could also use something like NancyFX that allows self hosting to expose an HTTP endpoint from each application to allow communication without the need for a physical file.

Check out: https://github.com/NancyFx/Nancy/wiki/Self-Hosting-Nancy

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