Skip to content

Commit

Permalink
Use System.Thread.Lock on .NET 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianeicher committed Nov 24, 2024
1 parent be3c5af commit 1142c4f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Common.AnsiCli/Net/AnsiCliCredentialProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ namespace NanoByte.Common.Net;
/// <param name="beforePrompt">An optional callback to be invoked right before the user is prompted for credentials</param>
public class AnsiCliCredentialProvider(Action? beforePrompt = null) : ICredentialProvider
{
#if NET9_0_OR_GREATER
private static readonly Lock _lock = new();
#else
private static readonly object _lock = new();
#endif

/// <inheritdoc/>
public NetworkCredential GetCredential(Uri uri, bool previousIncorrect = false)
Expand Down
6 changes: 5 additions & 1 deletion src/Common.AnsiCli/Tasks/AnsiCliTaskHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ protected override ICredentialProvider CredentialProvider
? new AnsiCliCredentialProvider(beforePrompt: RemoveProgressBar)
: null);

private readonly object _progressContextLock = new();
#if NET9_0_OR_GREATER
private static readonly Lock _progressContextLock = new();
#else
private static readonly object _progressContextLock = new();
#endif
private AnsiCliProgressContext? _progressContext;

/// <inheritdoc/>
Expand Down
4 changes: 4 additions & 0 deletions src/Common/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public static partial class Log
/// </summary>
public static void Error(Exception exception) => AddEntry(LogSeverity.Error, null, exception);

#if NET9_0_OR_GREATER
private static readonly Lock _lock = new();
#else
private static readonly object _lock = new();
#endif

/// <summary>
/// Adds a log entry.
Expand Down
4 changes: 4 additions & 0 deletions src/Common/Net/WindowsCliCredentialProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ namespace NanoByte.Common.Net;
[SupportedOSPlatform("windows")]
public class WindowsCliCredentialProvider(Action? beforePrompt = null) : WindowsCredentialProvider
{
#if NET9_0_OR_GREATER
private static readonly Lock _lock = new();
#else
private static readonly object _lock = new();
#endif

/// <inheritdoc/>
protected override NetworkCredential GetCredential(string target, WindowsCredentialsFlags flags)
Expand Down
4 changes: 4 additions & 0 deletions src/Common/Net/WindowsGuiCredentialProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ namespace NanoByte.Common.Net;
[SupportedOSPlatform("windows")]
public class WindowsGuiCredentialProvider : WindowsCredentialProvider
{
#if NET9_0_OR_GREATER
private static readonly Lock _lock = new();
#else
private static readonly object _lock = new();
#endif

/// <inheritdoc/>
protected override NetworkCredential GetCredential(string target, WindowsCredentialsFlags flags)
Expand Down

0 comments on commit 1142c4f

Please sign in to comment.