views:

3663

answers:

2

Is there a way of setting culture for a whole application? All current threads and new threads?

We have the name of the culture stored in a database, and when our application starts, we do

CultureInfo ci = new CultureInfo(theCultureString);
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;

But, of course, this gets "lost" when we want to do something in a new thread. Is there a way of setting that CurrentCulture and CurrentUICulture for the whole application? So that new threads also gets that culture? Or is it some event fired whenever a new thread is created that I can hook up to?

+5  A: 

This gets asked a lot. Basically, no there isn't. You have to do it manually at the start of each new thread (or ThreadPool function). You could perhaps store the culture name (or just the culture object) in a static field to save having to hit the DB, but that it about it.

Marc Gravell
kind of annoying... seems like you are right, hehe. So we do that now (and have the culture a static class), but we still have a problem with some threads that we do not have control over. Like processing threads in the microsoft report viewer. Found a work around though. Thank you for the info :)
Svish
What is the workaround?
Alex Reitbort
Who said anything about there being a workaround? This is how it is...
Marc Gravell
This is really annoying :( It would be nice if there was a way to set the Current(UI)Culture automatically for your application and have all new threads pick up that value.
Jedidja