tags:

views:

30

answers:

1

(probably a dumb question)

// Program_1.exe:
int num = 1;
using (Process process = new Process())
{
  process.StartInfo.FileName = "Program_2.exe";
  if (process.Start())
  {
    process.WaitForExit();
  }
}
Console.WriteLine(num.ToString()); // num should now equal 2

Psuedocode

// Program_2.exe:
// I want this program to change the value of a variable in Program_1.exe
Program_1.exe->num = 2;

Is this possible?

If so, how can I do it?

+1  A: 

You need to use some form of inter-process communication, such as WCF.

SLaks
To elaborate, Program_1 needs to deliberately expose some facility to allow Program_2 to affect its state. It would be a very, very bad thing if there were a standard way to freely modify the private state of an arbitrary program!
twon33
Okay, so there's no way to pass a pointer to `num` from *Program_1.exe* to *Program_2.exe* so that *Program_2.exe* can change the value addressed by that pointer? I just wanted to confirm to make sure. Thanks twon33, you make an excellent point.
JohnB
@John: Correct; you cannot do that in managed code. You can look into shared memory, but it's probably not a good idea.
SLaks