none
Setting CurrentUICulture to each thread RRS feed

  • Question

  •  

    I wanted to implement localization on my application. I am using culture specific resouce files and I should must say that .Net has very beautiful framework in place for implmenting localization and that rocks.

    In my application I read the culture to be selected from my config file and use that culture going forward. The problem that I am facing is when ever I create new thread I need to set this culture information to taht thread as well. Is there any way where in I can specify that threads that will be created here onwards should have a specific culture set, or may be created with the culture of the parent theread in which new threads are created. Since everytime I want to set the culcutre info to each thread that I create its bit painful.


    I also want to allow my users to change the language at run time, do I have to manually set the culture info of all the threads in my application or is there some automated way of doing it?


    Saurabh Surana
    Wednesday, September 3, 2008 6:09 AM

Answers

  • Customizing your program's culture to be different from the OS default can be very difficult to get right.  As you found out.  It is all the little I/O completion threadpool threads that are hard to keep under control.  A source of very subtle bugs that are hard to repro, typically due to the different collating rules for strings.  Not sure where you live but in most places in the world using the OS setting is plenty good enough for the user.

    If you are really committed to making this work, only ever update the UI from the UI thread.  That's pretty much a Windows requirement anyway.  Carefully review your code for any place where a string is generated.  Avoid sorted collections.  Make it a point to flush out the bugs by *not* changing the CurrentUICulture for any thread but your main UI thread.

    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Tuesday, September 9, 2008 8:41 AM
    Wednesday, September 3, 2008 11:51 AM
    Moderator