Normally you can get it by writing something like
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
But this way you can only get CultureInfo which was configured at the moment application was launched and will not update if the setting have been changed afterwards.
So, how to get CultureInfo currently configured in Control Panel -> Regional and Language Settings?
WriteLine("ISOCurrencySymbol:" + regionInfo. ISOCurrencySymbol); Console. WriteLine("Name:" + regionInfo.Name); This reads the information you have set in Windows 10 under "Regional & Language" > "Country or region".
Click the Start button, and then click Control Panel. Click Clock, Language, and Region, and then click Regional and Language Options.
regional settings. the settings in an operating system that pertain to the user's location, such as language, currency, and time zone.
As @Christian proposed ClearCachedData is the method to use. But according to MSDN:
The ClearCachedData method does not refresh the information in the Thread.CurrentCulture property for existing threads
So you will need to first call the function and then start a new thread. In this new thread you can use the CurrentCulture to obtain the fresh values of the culture.
class Program
{
private class State
{
public CultureInfo Result { get; set; }
}
static void Main(string[] args)
{
Thread.CurrentThread.CurrentCulture.ClearCachedData();
var thread = new Thread(
s => ((State)s).Result = Thread.CurrentThread.CurrentCulture);
var state = new State();
thread.Start(state);
thread.Join();
var culture = state.Result;
// Do something with the culture
}
}
Note, that if you also need to reset CurrentUICulture, you should do it separately
Thread.CurrentThread.CurrentUICulture.ClearCachedData()
Thread.CurrentThread.CurrentCulture.ClearCachedData()
looks like it will cause the culture data to be re-read when it is next accessed.
You can use Win32 API function GetSystemDefaultLCID. The signiture is as follow:
[DllImport("kernel32.dll")]
static extern uint GetSystemDefaultLCID();
GetSystemDefaultLCID function returns the LCID. It can map language string from the folowing table. Locale IDs Assigned by Microsoft
We ran into to this issue with our WinForms app and it was due to Visual Studio creating the [MyApp].vshost.exe process that is always running in the background whenever Visual Studio is open.
Turning off the MyApp -> Properties -> Debug -> "Enable Visual Studio hosting process" setting fixed this for us.
The vshost process is mainly used to improve debugging, but if you don't want disable the setting, you can kill the process as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With