Pregunta

Maybe its too late, but I have a static class for the sake of global variables in my winforms application. Now, I am realizing this may cause issues. The question is: "With the static class variables in my application, will it raise concurrency issues while its running in multi-user environment?".

If this is true, can anyone suggest a way to overcome it?

Thanks in Advance

¿Fue útil?

Solución

Short answer: No. Multi user environment means that multiple users are using your program, but every one is starting a new instance. Your static variables will not be shared across multiple processes and hence will only be a problem once your program consists of multiple threads.

However, static global variables are not a "good thing" (tm). You should avoid them because they will lead to problems once you do have multiple threads running in your process.

Otros consejos

Short answer : Yes, Simply use lock to prevent the concurrency issue when you try to modify the variable.

First, global variables are a bad idea, you should avoid using globals where possible.

If multiple threads are reading and writing to the same variables, you have a concurrency problem, yes. To avoid this, read/write the global variables on a single thread.

If you're unable to do that, you can lock access to the variables.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top