In C#, a class level variable would not be thread-safe (any exceptions to this? Let me know). So I would have to wrap the usage of this variable (like in a method in the same class), in a lock.
However, the very idea of using new makes me think that each class instance has its own instance etc and one instance variable is never shared, so the calls to the method never see anything that is shared data. So why would an instantiated class need locks on its class-level variables? Locks are only needed when two threads access the same memory address, but I thought this would always not be the case?
Thanks
You can create an instance of a class, and access it from multiple threads. For example:
Both of these tasks will execute on a background thread, and use the same instance – The one pointed to by “classInstance”. This requires synchronization if the class is mutable.