-1

In the control panel of Windows there is a combobox where we can change the regional format (controlPanel => Region => Formats (windows 10)). For example Persian or English

I want to retrieve this regional setting in my application.

I tried code like this:

        CultureInfo ci = CultureInfo.InstalledUICulture;
        var installed = ci.Name;

        ci = CultureInfo.CurrentUICulture;
        var currentUi = ci.Name;

        ci = CultureInfo.CurrentCulture;
        var current = ci.Name;

but installed and currentUi are always 'en-US' and current is 'fa-IR'

and when I change the format in the control panel they don't change.

Stefan
  • 14,240
  • 9
  • 51
  • 69
M. G. Lee
  • 153
  • 1
  • 10
  • Isn't `fa-IR` the one you where expecting? Besides have you tried: `start application => check culture => change region format => restart application and check again`? I think it only changes after you restart the application. – Stefan Sep 11 '16 at 07:39
  • i restart my app but it does not change – M. G. Lee Sep 11 '16 at 07:43
  • The control panel applet lets you change formats for a region that is not the current region. Not actually very useful, is it? Still, it is necessary to configure the formats when a program changes its default culture. Nothing in the snippet suggest that you are doing this. – Hans Passant Sep 11 '16 at 07:54

1 Answers1

-1

I used this code.

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;

And then we use culture.Name. And in this case it's not necessary to close and reopen the program.

pix
  • 1,224
  • 18
  • 30
M. G. Lee
  • 153
  • 1
  • 10