0

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?

dandan78
  • 13,328
  • 13
  • 64
  • 78
Tobz
  • 3
  • 2

1 Answers1

0

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.

Community
  • 1
  • 1
Alex K.
  • 171,639
  • 30
  • 264
  • 288
  • This link helped me: http://www.hanselman.com/blog/TheWeeklySourceCode31SingleInstanceWinFormsAndMicrosoftVisualBasicdll.aspx – Tobz Aug 30 '12 at 14:57