Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/mscorlib/corefx/System/Globalization/CultureInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ public partial class CultureInfo : IFormatProvider
//The parent culture.
private CultureInfo m_parent;

static AsyncLocal<CultureInfo> s_asyncLocalCurrentCulture;
static AsyncLocal<CultureInfo> s_asyncLocalCurrentUICulture;

static void AsyncLocalSetCurrentCulture(AsyncLocalValueChangedArgs<CultureInfo> args)
{
s_currentThreadCulture = args.CurrentValue;
}

static void AsyncLocalSetCurrentUICulture(AsyncLocalValueChangedArgs<CultureInfo> args)
{
s_currentThreadUICulture = args.CurrentValue;
}

//
// The CultureData instance that reads the data provided by our CultureData class.
//
Expand Down Expand Up @@ -311,7 +324,13 @@ public static CultureInfo CurrentCulture
{
throw new ArgumentNullException("value");
}
s_currentThreadCulture = value;

if (s_asyncLocalCurrentCulture == null)
{
Interlocked.CompareExchange(ref s_asyncLocalCurrentCulture, new AsyncLocal<CultureInfo>(AsyncLocalSetCurrentCulture), null);
}
// this one will set s_currentThreadCulture too
s_asyncLocalCurrentCulture.Value = value;
}
}

Expand Down Expand Up @@ -355,8 +374,14 @@ public static CultureInfo CurrentUICulture
}

CultureInfo.VerifyCultureName(value, true);

if (s_asyncLocalCurrentUICulture == null)
{
Interlocked.CompareExchange(ref s_asyncLocalCurrentUICulture, new AsyncLocal<CultureInfo>(AsyncLocalSetCurrentUICulture), null);
}

s_currentThreadUICulture = value;
// this one will set s_currentThreadUICulture too
s_asyncLocalCurrentUICulture.Value = value;
}
}

Expand Down