8

I am writing a contact management program. I know how to read command-line arguments, and perform different methods based on what I find.

For example, program.exe "John Doe" will start a new instance of the program and open up the first contact it finds named John Doe, program.exe -s John will start a new instance of the program and search for contacts named "John," whereas simply running program.exe will open start a new instance of the program with a blank search screen.

I would like to only run a single instance of the program, however. So when another program calls program.exe "John Doe", if there is already a process running, the arguments will be passed to that process and switch to a new search rather than opening a new window.

I know that this requires looking for previously running processes and inter process communication, but I've not done much of either in .Net and am having trouble getting started in the right direction or finding any good tutorials on the specific subject.

dlras2
  • 8,416
  • 7
  • 51
  • 90

3 Answers3

4

http://www.hanselman.com/blog/TheWeeklySourceCode31SingleInstanceWinFormsAndMicrosoftVisualBasicdll.aspx

Visual basic dll has a WindowsFormsApplicationBase that has StartupNextInstance event in which you can get the arguments of the second instance and the second instance can kill itself on detecting other instances.

This has been asked already C# : how to - single instance application that accepts new parameters?

Community
  • 1
  • 1
Muhammad Hasan Khan
  • 34,648
  • 16
  • 88
  • 131
1

may be this post can help you. See Here , also using IPC Channel

Community
  • 1
  • 1
TalentTuner
  • 17,262
  • 5
  • 38
  • 63
1

One way to do it would be to have program.exe host a WCF service (as you seem to have guessed from your tag). Then, when another instance is started, with command-line arguments, it would be a WCF client to that service, and send the arguments to the service, then exit.

John Saunders
  • 160,644
  • 26
  • 247
  • 397