Static Member Behavior with Multiple Application Instances - C #

I am working on my window and I am using some static elements.

public class MyParameter { public static string connectionString = "..."; } 

Now, if I install my application on a computer and open two instances of the same application. Will "connectionString" be shared between two instances? Or does each instance have a connectionString?

+4
source share
3 answers

The variable static or not is part of your application memory. When you open 2 instances of your application, you create different memory cells in the OS, so there is no connection between the two variables at all.

If you want to create one (relation), you need to look at the various IPC (Inter Process Communication) methods available in the OS, for example:

+6
source

Each instance.

Static elements are distributed based on AppDomain . If you were to create a new AppDomain from your current .. they will be different.

+2
source

No. Each application instance is isolated from each other using AppDomain. Thus, each instance of the application will run in a separate AppDomain and will not be able to access variables from another domain. To interact with another domain, we need to use Remoting, WCF Service

+2
source

Source: https://habr.com/ru/post/1487853/


All Articles