Reputation: 5750
I have two executables that reference the same Class Library. In the class library I have a static variable. How can that static variable persists on the two different executables?
This is how it looks:
public class MyClass
{
public static string MyVar;
}
App 1:
public class MyApp1
{
public void SomeMethod()
{
MyClass.MyVar = "hello";
}
}
App 2:
public class MyApp2
{
public void SomeOtherMethod()
{
if(MyClass.MyVar == "hello")
DoSomething();
}
}
Upvotes: 2
Views: 1901
Reputation: 33474
This will sound stupid.
But write it to a text file on a common location & read from it when needed.
Upvotes: 4
Reputation: 50722
The only way to share data betwin appdomains is remoting (WCF, .net remoting or etc.)
Upvotes: 3
Reputation: 1500785
There's nothing built-in to do this. Would you want the static variables to be persistent across invocations of the executable as well, or just while both were running at the same time? Basically you're looking at "normal" persistence mechanisms (and thinking about liveness - detecting when one process needs to reload its state).
I would personally try to design around this to avoid even wanting to do it. Consider having a separate service which both apps talk to instead.
Upvotes: 8