0

I have a WPF client application which can have maximum of one instance at any point of time, if the user runs the second instance it should pass the input arguments to first instance of application and quit. i.e i run the first instance with argument "hello", and again starting new instance of same appln with new argument "welcome", noe the second instance should pass the data "welcome" to first instance and exit.

Other that WCF and .Net remoting, is there any easiest and clean way to do it?

Currently I'm able to make the first instance as active, using WindowsEventHandle, but could not able to pass the data. This is in same machine within same login

Mathiyazhagan
  • 1,389
  • 3
  • 13
  • 37

3 Answers3

0

Very basic, but you could simply write to a file and have the other application instance monitor the file for new commands with unique IDs for messages based on the current timestamp down to millisecond.

user1438082
  • 2,740
  • 10
  • 48
  • 82
0

Yes of course. We tried multiple approaches, but the one using mutex`es seems to work the best.

here a some samples : How can I check for a running process per user session?

a good article about mutex`es http://odetocode.com/blogs/scott/archive/2004/08/20/the-misunderstood-mutex.aspx

a simple implementation https://stackoverflow.com/a/19326/444149

If You search deeper, I'm sure there's a good sample in SO which shows how mutex events can be used to trigger something in another app instance

Community
  • 1
  • 1
Marty
  • 3,485
  • 8
  • 38
  • 69
0

Have a look at Memory-Mapped Files Since .NET 4 they have been available and can even share memory with unmanaged applications.

Non-persisted memory-mapped files Non-persisted files are memory-mapped files that are not associated with a file on a disk. When the last process has finished working with the file, the data is lost and the file is reclaimed by garbage collection. These files are suitable for creating shared memory for inter-process communications (IPC).

Emond
  • 50,210
  • 11
  • 84
  • 115