Do instances of the same application share static objects?

3

I'm developing a Windows Form application in C #, and this application can run simultaneously on the same computer multiple times.

And I'm not sure if I should use static objects (classes, functions, variables, etc.) because they might be given different values at program startup.

So I would like to know if the various instances of the same program will share the same static variable information?

Example:

  • There is a static A variable;
  • When the first instance is opened it gets 1
  • When the second instance is opened it gets 2

In the first instance the variable A will remain 1 ?

    
asked by anonymous 17.10.2018 / 21:22

1 answer

1

No, this never happens, an instance is a separate process, and in fact one has no knowledge that there is another, it is totally separate and there is no way to share between any parts of memory, whether it is static or not . So yes, it will continue to be worth the same amount. You can see more in Is there a difference between Program, Thread and Process? .

Unless you use some specific mechanism for this, such as Memory Mapped File, and only what is placed inside it is that it can be seen by another instance that opens the same file.

    
17.10.2018 / 22:25