views:

997

answers:

3

I'm having an issue with some byte conversions and a few of my calcualtions in one of my applications. I was able to contribute it to the person running it having an Italian Culture setting in windows. So my question is: What is the best way to for "en-US" on any computer running my application. I have a code sample below, but I am unsure if any thread I use will inhert it. Any ideas?

    [STAThread]
    static void Main()
    {
        System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
        System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

        ...
    }
A: 

According to this accepted answer over at Experts Exchange, your code sample is supposed to work the way you describe, i.e. it will change the culture for the entire application.

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CSharp/Q_22914060.html

Robert Harvey
+1  A: 

Your code will set the culture of the current thread, but any new threads that are created will not have this culture 'inherited'. You have to set the culture you require yourself. (I believe that any new threads will be created with the installed Windows culture, but I'm prepared to be proved wrong on that.)

This is answered in this post: http://stackoverflow.com/questions/468791/c-setting-currentculture-and-currentuiculture-of-an-application

Personally, I find this behaviour annoying, but that's the way it is.

Andy
+2  A: 

The problem you describe is the reason InvariantCulture exists. Rather than change your application's culture, you should do your behind-the scenes data manipulation/persistence with the invariant culture and then let the user's culture determine how values are rendered.

dahlbyk