Question

2 local and running applications: App #1 periodically (timer1 @30sec) writes "ping" to a shared/"crossprocess" string. App #2 periodically checks (timer2 @60sec) if shared string == "ping" and overwrites it with "pong". As timer2 > timer1 App #2 will always receive/read the string as "ping". If not then I can certainly assume that App #1 crashed/hangs and restart it.

I know this can be done really easy with Clipboard...

Clipboard.Clear();
Clipboard.SetData("checkthis", "ping");
.
.
.
object clip = Clipboard.GetData("checkthis")
if (clip.ToString() == "ping")
{
    Clipboard.Clear();
    Clipboard.SetData("checkthis", "pong");
}

...but I think it is a really bad idea to use Clipboard as the user can easily mess it up. Is there an other solution as easy to use as Clipboard?

Was it helpful?

Solution

Memory-mapped files are one approach: http://msdn.microsoft.com/en-us/library/vstudio/dd997372(v=vs.100).aspx will do the job.

Named Pipes are another.

An ordinary file work, too. Just have each process put a FileSystemWatcher on the file and listen for changes.

OTHER TIPS

I think this thread in SO will help you solve your problem. Good luck!

Static members behavior with multiple instance of application - C#

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top