0

I have an application developted with Visual C++ 2008 Express Edition under Windwos XP, which runs propertly on one computer, where the default langaunge is set to English. However, if run the same application on a different computer with default language German, I run into troubles because a predefined string Infinity is not recoginzed during conversion to double using ToDouble, because on the German platform the string should be Unendlich. In particular the mscorlib throws correctly a FormatException.

How can I force the application to run with the English locale? I could not yet find any option...

Thanks for any hint.

3 Answers 3

6

You can set the current locale to English with:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);

That will force US English in the current thread. If you do that in the main Windows Forms thread, then your UI culture will always be English. See http://msdn.microsoft.com/en-us/library/b28bx3bh(v=VS.100).aspx for more info.

As Hans pointed out in his comment, this doesn't affect pool threads and can lead to some hard to find bugs. It turns out that there is no global setting that will make every thread use the culture that you define. If you want that functionality, you'll have to make your own application-wide setting and ensure that all threads use it.

Also good to read would be Globalizing Windows Forms.

2
  • 1
    It doesn't, threadpool threads that run I/O completion calls and what-not will still run in the system language. This can cause very subtle and hard to diagnose bugs. A SortedList suddenly isn't sorted anymore for example. Sep 20, 2010 at 16:08
  • Thanks! Too bad that there is no global option. I will have a look a the mentioned links, though. Sep 20, 2010 at 17:41
1

Use Convert::ToDouble(str, System::Globalization::CultureInfo::InvariantCulture);

0
0

Convert.ToDouble(stringValue, System.Globalization.CultureInfo.InvariantCulture);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.