Thread.CurrentCulture Property (System.Threading)

Switch View :
ScriptFree
.NET Framework Class Library
Thread.CurrentCulture Property

Gets or sets the culture for the current thread.

Namespace:  System.Threading
Assembly:  mscorlib (in mscorlib.dll)
Syntax

Visual Basic
Public Property CurrentCulture As CultureInfo
C#
public CultureInfo CurrentCulture { get; set; }
Visual C++
public:
property CultureInfo^ CurrentCulture {
	CultureInfo^ get ();
	void set (CultureInfo^ value);
}
F#
member CurrentCulture : CultureInfo with get, set

Property Value

Type: System.Globalization.CultureInfo
A CultureInfo representing the culture for the current thread.
Exceptions

Exception Condition
NotSupportedException

The property is set to a neutral culture. Neutral cultures cannot be used in formatting and parsing and therefore cannot be set as the thread's current culture.

ArgumentNullException

The property is set to null.

Examples

The following code example shows the threading statement that allows the user interface of a Windows Forms to display in the culture that is set in Control Panel. Additional code is needed.

Visual Basic

' Compile with option t:winexe /r:System.dll,System.Windows.Forms.dll.

Option Explicit
Option Strict

Imports System
Imports System.Threading
Imports System.Windows.Forms

Public Class UICulture
    Inherits Form

    Sub New()

        ' Set the user interface to display in the
        ' same culture as that set in Control Panel.
        Thread.CurrentThread.CurrentUICulture = _
            Thread.CurrentThread.CurrentCulture

        ' Add additional code.
    End Sub

    <STAThreadAttribute> Shared Sub Main()
        Application.Run(New UICulture())
    End Sub

End Class


C#

// Compile with option /t:winexe.

using System;
using System.Threading;
using System.Windows.Forms;

class UICulture : Form
{
    public UICulture()
    {
        // Set the user interface to display in the
        // same culture as that set in Control Panel.
        Thread.CurrentThread.CurrentUICulture = 
            Thread.CurrentThread.CurrentCulture;

        // Add additional code.
    }

    [STAThreadAttribute]
    static void Main()
    {
        Application.Run(new UICulture());
    }
}


Visual C++

#using <system.dll>
#using <System.Drawing.dll>
#using <system.windows.forms.dll>

using namespace System;
using namespace System::Threading;
using namespace System::Windows::Forms;
ref class UICulture: public Form
{
public:
   UICulture()
   {

      // Set the user interface to display in the
      // same culture as that set in Control Panel.
      Thread::CurrentThread->CurrentUICulture = Thread::CurrentThread->CurrentCulture;

      // Add additional code.
   }

};


[STAThreadAttribute]
int main()
{
   Application::Run( gcnew UICulture );
}



Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library
.NET Framework Security

Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also

Reference

Community Content

Justin Mellor
Change with Neutral Cultures in .NET 4

As mentioned, .NET 4 allows neutral cultures to be used for the CurrentCulture. This is because the format rules are taken from the specific culture which is most dominant for the neutral culture.

See http://msdn.microsoft.com/en-us/netframework/dd890508


dgon
Not throwing when neutral culture is set
In the version 4.0 of the framework, setting the property to a neutral culture (such as "es") no longer throws a NotSupportedException.
Please ammend the documentation to reflect that reality.