When a website simultaneously hits the same static method that has non-static variables, are these variables static even though not declared static? I would assume so, but I had to ask.
Another option would be that different executions of the same code have different internal variables, so this code wouldn’t produce unexpected string lengths for example:
public static class MyClass
{
public static int getResult(string ext)
{
int length = est.length; // One place in RAM or multiple?
Thread.Sleep(5000); // Does this stop program execution for others?
return length;
}
}
Question summary:
- Are static method variables that are not declared static implied static, i.e. simultaneous execution of static code will affect each other?
- or do these variables have their own storage each?
- and does Thread.Sleep(5000) in a static method stop all user’s execution?
You’re showing local variables. So no, those aren’t static variables. Each time you invoke the method (including if it invoked itself recursively), you get a new set of variables. Different threads will not be sharing those variables. Note that this has nothing to do with the class being a static class. You need to differentiate between:
Thread.Sleeponly makes the current thread sleep – if your application has multiple threads, the others will still be able to execute.