System.Globalization.CultureInfo.CurrentUICulture Property

Gets the System.Globalization.CultureInfo object that represents the current user interface culture used by the Resource Manager to look up culture-specific resources at run time.

Syntax

public static CultureInfo CurrentUICulture { get; }

Value

Documentation for this section has not yet been entered.

Remarks

The current UI culture is a per-thread property. That is, each thread has its own current UI culture. This read-only property is equivalent to retrieving the System.Globalization.CultureInfo object returned by the System.Threading.Thread.CurrentThread.CurrentUICulture property. When a thread is started, its UI culture is initially determined as follows:

  • By retrieving the culture that is specified by the CultureInfo.DefaultThreadCurrentUICulture property in the application domain in which the thread is executing, if the property value is not null.

  • By calling the Windows GetUserDefaultUILanguage function.

Note:

In the compact, the CultureInfo.CurrentUICulture property is read-only. The current UI culture is determined by the system's regional settings and cannot be changed programmatically.

To change the user interface culture used by a thread, set the System.Threading.Thread.CurrentUICulture property to the new culture. If you explicitly change a thread's UI culture in this way, that change persists if the thread crosses application domain boundaries.

Explicitly Setting the Current UI Culture

Although the CultureInfo.CurrentUICulture property is read-only, you can change its value by explicitly setting the System.Threading.Thread.CurrentUICulture property of the current thread. The current UI culture can be set to either a specific culture (such as en-US or de-DE) or to a neutral culture (such as en or de). The following example sets the current UI culture to fr-FR or French (France).

code reference: System.Globalization.CultureInfo.CurrentUICulture#1

In a multithreaded application, you can explicitly set the UI culture of any thread by assigning a System.Globalization.CultureInfo object that represents that culture to the thread's System.Threading.Thread.CurrentUICulture property. When the UI culture of a thread is set explicitly, that thread retains the same culture even if it crosses application domain boundaries and executes code in another application domain.

Implicitly Setting the Current UI Culture

When a thread, including the main application thread, is first created, by default its current UI culture is set as follows:

  • By using the culture defined by the CultureInfo.DefaultThreadCurrentUICulture property for the current application domain if the property value is not null.

  • By using the system's default culture. On systems that use the Windows operating system, the common language runtime calls the Windows GetUserDefaultUILanguage function to set the current UI culture. GetUserDefaultUILanguage returns the default UI culture set by the user. If the user has not set a default UI language, it returns the culture originally installed on the system.

If the thread crosses application boundaries and executes code in another application domain, its culture is determined in the same way as that of a newly created thread.

Note that if you set a specific UI culture that is different from the system-installed UI culture or the user's preferred UI culture, and your application starts multiple threads, the current UI culture of those threads will be the culture returned by the GetUserDefaultUILanguage function, unless you assign a culture to the CultureInfo.DefaultThreadCurrentUICulture property in the application domain in which the thread is executing.

Security Considerations

Changing the culture of the current thread requires a System.Security.Permissions.SecurityPermission permission with the System.Security.Permissions.SecurityPermissionFlag.ControlThread value set.

Note:

Manipulating threads is dangerous because of the security state associated with threads. Therefore, this permission should be given only to trustworthy code, and then only as necessary. You cannot change thread culture in semi-trusted code.

Requirements

Namespace: System.Globalization
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0