Question

It's my first post, so forgive anything misplaced.

We are developing an ASP.Net MVC 5 application that offers multiple cultures to end-users. The Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture are set in the Application_AcquireRequestState() of the Global.asax.cs file.

As far as I am aware, every request to the web application fires off a new thread. I have created a static class that provides easy access to some date-format strings etc. depending on the culture.

My question is, are there any concerns accessing this static class' methods and get-accessors from a request thread's context (e.g. controller) that may have a different culture? Which culture will the static class have?

Was it helpful?

Solution

The class itself doesn't have any culture as such. It's the thread that accesses this class that has a culture and the thread's culture is used in a class (static or not).

Static really refers to how the class's state is shared across different threads. Your static class can be stateless (i.e. it doesn't store an data, often the case with helper type of static classes) which will create less problems for you.

If you store any state in your static class, you have to be careful for 2 reasons:

  • in general, it's harder to control access to statically held data in a multithreaded environment,

  • if any data you store is culture-specific, you may have problems with interpreting this data when using threads with different culture.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top