Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make my running .NET application be able to receive commands while it is running?

How can I make my already running C# Windows Form Application be able to receive commands from the command line while it is already running?

For example: if my application is playing a video now then I want to be able to type on the command line "MyApp /stop" so that while the application is still running it stops the playing the video without exiting from current session.

like image 910
CSharpBeginner Avatar asked Jun 02 '10 22:06

CSharpBeginner


2 Answers

From your question it seems that your first process is still running and you start a second instance of it, and you wish that instance to communicate with the first.

What you are looking for is called inter-process communication (IPC). The standard way of doing this in .NET is to use Windows Communication Foundation (WCF).

like image 179
Mark Byers Avatar answered Sep 28 '22 09:09

Mark Byers


One way would be to make your app a singleton, and whenever another instance is run, it will pass arguments to the already running process.

Example: http://www.codeproject.com/KB/cs/SingletonApplication.aspx

like image 37
Amirshk Avatar answered Sep 28 '22 09:09

Amirshk