C# Question – I’m trying to determine whether it is OK to use a static method where, within the method it does have some local variables it uses. Are the local variables “shared” across usages of the method? What happens for example if the static method is being called/used at the same time from different threads? Does one thread block until the other is complete etc?
Perhaps the generalised question is, in a threaded application, when should one “not” being using a static method?
Local variables within the method live on the stack and each thread has its own stack. Therefore it’s safe for multiple threads to use the method.
However if the method itself uses static variables then you should use appropriate MT protection. Also external methods you may be calling need to be safe…