Normally you can get it by writing something like
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
But this way you can only ge
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.
There are the classes CultureInfo
and TextInfo
from the namespace System.Globalization
. Both classes get several windows regional settings defined in the control panels. The list of available settings is in the documentation.
For example:
string separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator;
is getting the list separator for the program which is running.
Thread.CurrentThread.CurrentCulture.ClearCachedData()
looks like it will cause the culture data to be re-read when it is next accessed.
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()
Try to find settings you want in SystemInformation
class or look into WMI using the classes in System.Management/System.Diagnostics
, you can use LINQ to WMI too
[DllImport("kernel32.dll")]
private static extern int GetUserDefaultLCID();
public static CultureInfo CurrentCultureInRegionalSettings => new CultureInfo(GetUserDefaultLCID());