Search code examples
c#localecultureinfo

Where can I find user culture if not in Thread.CurrentCilture


Is it possible to find user's culture if I cannot use Thread.CurrentCulture nor (naturally) CultureInfo.CurrentCulture?
I cannot use them because I'm just modifying small part of the huge project, and Thread.CurrentCulture is set to different culture somewhere in it.
One possible solution is to remember original culture when Thread.CurrentCulture is being set. But it there a way to get proper user's culture no matter what?


Solution

  • You can p/invoke GetUserDefaultLCID() and pass the resulting value to the CultureInfo constructor that takes an int:

    [DllImport("kernel32.dll")]
    static extern int GetUserDefaultLCID();
    

    CultureInfo defaultUserCulture = new CultureInfo(GetUserDefaultLCID());