I know that a static variable used in a web application is shared for all users across the web application. If I have a library (DLL) that uses some static private variable, do all applications using that library share the value of that variable?
For example, say I have the following code in my DLL:
private static bool isConnected = false; public static void Connect() { // TODO: Connect. isConnected = true; } public static void Disconnect() { // TODO: Disconnect. isConnected = false; }
Then in Application A, I call myDLL.Connect()
which sets the value of isConnected
to True
. Then I have some Application B that does the same thing. If Application A later calls myDLL.Disconnect()
, does Application B see isConnected
as False
because the two applications share the same DLL file with a static variable? The DLL file would, in this case, be literally the same file in the same file path.
(I previously asked a somewhat similar question about web applications here. It is not related.)
Class Variables and MethodsA static variable is shared by all instances of a class. Only one variable created for the class.
static attributes exist independently of any instances of a class and may be accessed even when no instances of the class have been created. You can compare a static variable with a shared variable. A static variable is shared by all the objects of a class.
In reality, "yes" the processes do have full "access" to the globals, at the very least through the funtion calls to the library.
The static variables are stored in the data segment of the memory. The data segment is a part of the virtual address space of a program. All the static variables that do not have an explicit initialization or are initialized to zero are stored in the uninitialized data segment( also known as the BSS segment).
No they won't. They are loaded in separate AppDomains
and cannot see each other's instances.
Even if they refer to same physical file, each application gets its own private instance of the assembly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With