Question

I have 2 Console Applications (Console1 and Console2) in one solution. Both applications reference a class library (CL). CL contains a static class (SC) which contains fields that are set per constructor.

My question is if I call the static class within Console1 and the constructor of the SC is called upon first calling any of Console1's containing static methods and fields are set within SC. Now if I run Console2 concurrently, though independently, and also access the SC, what is the precise scope of the static class SC? Will any changes such as calling its constructor that originated from within Console1 have any bearing whatsoever on how the SC behaves when being used in Console2?

Was it helpful?

Solution

The scope is the AppDomain.

Because you have two separate processes, you have two separate AppDomains and two separate "instances" of the static class. There is no state sharing - none at all.

OTHER TIPS

If Console1 and Console2 are running independently like two completely separate exe files, SC constructor will be called again, else it won't.

Console 1 and 2 are running as separate processes. The assemblies are loaded per process (per app domain to be precise), and each will initialize the static constructor and such. Therefore the 'running instances of the assemblies' are completely separate.

Your question may be about static classes but the answers you are getting will all boil down to this: If you run two separate instances of a project the classes used in one instance will not interact with the other. In fact you could run two instances of the same project and you will have no problems. It is no different to running two instances of Microsoft word

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top