Question

I there any way to start an instance of a C# .NET-program and then call it again using a command-line option to, for example, insert a text in a text box?

Use case: 1) Double click / start: MyProgram.exe (will start the GUI) 2) From command line: MyProgram.exe -addText "Text to add" (my "favorite" editor will launch this command when I press some keyboard combination)

I.e. I want to pass commands to an already running instance of my (GUI) program.

I have been thinking about WCF but can't see any solution there...

Of course I can create a file which my program polls every X ms, reads the contents, performs the command and deletes it but isn't there any more elegant solution?

Was it helpful?

Solution

Yes, this is the same as having a single instance of an application responding to the launch of an associated file type.

See Opening a "known file type" into running instance of custom app - .NET or search here for WindowsFormsApplicationBase which is what handles the wiring up of instances for you.

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