I was wondering what it means for a multi-threaded system to use static classes in the following ways:
- Without using a service:
Multiple instances of a Class A are using the same static class B for some random calculations (eg. System.Math) - Using WCF services:
a. Having 1 single WCF service doing what is described in 1.
b. Having several WCF services, each having 1 instance of a Class A using the same static class B for some random calculations
c. Having several WCF services, each having more than 1 instances of a Class A, all using the same static class B for some random calculations
From what I understand, using static classes as per 2.b. is the only proper option for multi-threaded systems as each WCF service will create its own copy/instance of the static class. All the other options will share the same static class and are therefore not allowing for multi-threading.
Is that about right?
What does it mean for the other options though? Is there a way to make static classes somehow instantiable? Thinking about System.Math, I cannot really just go and edit the source code.
Or is it common practice to just cope with it by adding a lock where these static classes are being used?
Maybe a singetone should rather be used than static when possible?