0

I am looking for the best approach to communicate between separate executables.

The approach I have tried is to create a separate class library that contains the static class SharedVariables and contains the global static variable MyVariable. I then add this project as a reference to project1 and project2 and reference MyVariable. This compiles fine.

The problem I am having is when running project1.exe and project2.exe (in the same directory). In project1.exe I set SharedVariablesMyVariable to true and have a thread in project2 that does something when SharedVariables.MyVariable is set to true. Project2 never sees this change to SharedVariables.dll.

Am I going about this the wrong way? Should I be using an interprocess communication solution?

Matt
  • 1,017
  • 2
  • 11
  • 27
  • You'll need to use some form of IPC. For local machine use named pipes or shared memory. Both of which are faster than WCF due to running in kernel mode as opposed to WCF which generaly uses a network redirector –  Aug 20 '15 at 15:58
  • 1
    possible duplicate of [What is the best choice for .NET inter-process communication?](http://stackoverflow.com/questions/84855/what-is-the-best-choice-for-net-inter-process-communication) –  Aug 20 '15 at 16:00

1 Answers1

0

Communication between processes is not as easy as adding a reference to the project in visual studio. Once the applications are compiled, they are two different entities. Have a look at inter-process communication. In C#, there is NamedPipeClientStream and NamedPipeServerStream. They are used to send information from a server to a client usually on a local computer. With this, you can write some "network" code to synchronize the two values.

Philippe Paré
  • 4,279
  • 5
  • 36
  • 56