views:

2108

answers:

2

In a .net 2 winforms application, what's a good way to set the culture for the entire application?
Setting CurrentThread.CurrentCulture for every new thread is repetitive and error-prone.
Ideally I'd like to set it when the app starts and forget about it.

+3  A: 

The culture for a thread in .NET is the culture for the system. There is no way to override that in .NET, you'll have to continue setting the CurrentCulture for each new thread.

Peter Ritchie
> the culture for the systemstrictly speaking, the culture corresponding to the regional settings of the current user.
Joe
A: 

You can set application current culture this way:

static void Main()
{
    System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("fi-FI");
    Application.CurrentCulture = cultureInfo;
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
}

I'm not sure if it helps, because I have never tested it with threads.

edit: it doesn't work. I think you have to set current culture in every thread.

Vertigo
I tried your solution and it made no difference.
Douglas Tosi
`Application.CurrentCulture` delegates to `Thread.CurrentThread.CurrentCulture` so it only sets it for the main thread of the application.
adrianbanks