Skip to content

Commit

Permalink
Switched from SemaphoreSlim lock to AsyncNonKeyedLocker (#1184)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCiliaVincenti committed Apr 21, 2024
1 parent 12b590d commit 74f99b4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
4 changes: 2 additions & 2 deletions DiscordChatExporter.Core/DiscordChatExporter.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="AsyncKeyedLock" Version="6.2.4" />
<PackageReference Include="AsyncKeyedLock" Version="6.3.4" />
<PackageReference Include="CSharpier.MsBuild" Version="0.26.7" PrivateAssets="all" />
<PackageReference Include="Gress" Version="2.1.1" />
<PackageReference Include="JsonExtensions" Version="1.2.0" />
Expand All @@ -12,4 +12,4 @@
<PackageReference Include="YoutubeExplode" Version="6.3.10" />
</ItemGroup>

</Project>
</Project>
11 changes: 3 additions & 8 deletions DiscordChatExporter.Gui/ViewModels/Framework/DialogManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using AsyncKeyedLock;
using MaterialDesignThemes.Wpf;
using Microsoft.Win32;
using Stylet;
Expand All @@ -10,7 +10,7 @@ namespace DiscordChatExporter.Gui.ViewModels.Framework;

public class DialogManager(IViewManager viewManager) : IDisposable
{
private readonly SemaphoreSlim _dialogLock = new(1, 1);
private readonly AsyncNonKeyedLocker _dialogLock = new();

public async ValueTask<T?> ShowDialogAsync<T>(DialogScreen<T> dialogScreen)
{
Expand All @@ -34,16 +34,11 @@ void OnScreenClosed(object? closeSender, EventArgs closeArgs)
dialogScreen.Closed += OnScreenClosed;
}

await _dialogLock.WaitAsync();
try
using (await _dialogLock.LockAsync())
{
await DialogHost.Show(view, OnDialogOpened);
return dialogScreen.DialogResult;
}
finally
{
_dialogLock.Release();
}
}

public string? PromptSaveFilePath(string filter = "All files|*.*", string defaultFilePath = "")
Expand Down

0 comments on commit 74f99b4

Please sign in to comment.