Skip to content

Commit 5993dbc

Browse files
committed
make CultureContext treadsafe
1 parent 149e592 commit 5993dbc

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

test/Remote.Linq.Tests/TestHelper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Remote.Linq.Tests;
1010
using System.Collections.Generic;
1111
using System.Globalization;
1212
using System.Linq;
13+
using System.Threading;
1314
using System.Threading.Tasks;
1415
using Xunit.Sdk;
1516
using MethodInfo = System.Reflection.MethodInfo;
@@ -84,17 +85,20 @@ public static bool IsCollection(this Type type)
8485

8586
private sealed class CultureContext : IDisposable
8687
{
88+
private static readonly SemaphoreSlim _semaphore = new(1, 1);
8789
private readonly CultureInfo _culture;
8890

8991
public CultureContext(CultureInfo culture)
9092
{
93+
_semaphore.Wait();
9194
_culture = CultureInfo.CurrentCulture;
9295
CultureInfo.CurrentCulture = culture;
9396
}
9497

9598
public void Dispose()
9699
{
97100
CultureInfo.CurrentCulture = _culture;
101+
_semaphore.Release();
98102
}
99103
}
100104

0 commit comments

Comments
 (0)