Application c:\pinkPanther.exe is running and it is application i wrote in c#. Some other application starts c:\pinkPanther.exe purpleAligator greenGazelle OrangeOrangutan and i would like not to start new instance of c:\pinkPanther.exe with these arguments, but to currently running c:\pinkPanther.exe register it and react to it somehow.
How to do it?
EDIT!!!: i'm very sorry about pinkPanther.exe and ruzovyJeliman.exe that caused the confusion - i translated question from my native language and missed it :(
This is assuming your application is a WinForms app, as that will make it easier to keep it open. This is a very simple example, but it will show you the basics:
Create an Application class inheriting from
WindowsFormsApplicationBase
. This base class contains built-in mechanisms for creating a single-instance application and responding to repeated calls on the commandline with new arguments:All you have to change in
Main()
is callRun()
on your new class rather thanApplication.Run()
:WindowsFormsApplicationBase
has some other capabilities you can explore, as well.To communicate with the other instance of the application, you need some sort of inter-process communication. Apparently, WCF is the recommended form of IPC in .Net. You can do that with code like this (using WPF, but WinForms would be similar):