Skip to content

Commit

Permalink
WPF: Fix close window confirm dialog not showing up
Browse files Browse the repository at this point in the history
  • Loading branch information
Genteure committed Jun 26, 2021
1 parent e66332b commit 70d433e
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions BililiveRecorder.WPF/NewMainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,31 @@ private void Window_StateChanged(object sender, EventArgs e)

public bool PromptCloseConfirm { get; set; } = true;

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
#pragma warning disable VSTHRD100 // Avoid async void methods
private async void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
#pragma warning restore VSTHRD100 // Avoid async void methods
{
if (this.PromptCloseConfirm && !this.CloseConfirmed)
{
e.Cancel = true;
_ = Task.Run(async () =>

if (await this.CloseWindowSemaphoreSlim.WaitAsync(0))
{
if (await this.CloseWindowSemaphoreSlim.WaitAsync(0))
try
{
try
{
if (await new CloseWindowConfirmDialog().ShowAsync() == ContentDialogResult.Primary)
{
this.CloseConfirmed = true;
this.CloseWindowSemaphoreSlim.Release();
_ = this.Dispatcher.BeginInvoke(this.Close, DispatcherPriority.Normal);
return;
}
}
catch (Exception) { }
finally
if (await new CloseWindowConfirmDialog().ShowAsync() == ContentDialogResult.Primary)
{
this.CloseWindowSemaphoreSlim.Release();
this.CloseConfirmed = true;
_ = this.Dispatcher.BeginInvoke(this.Close, DispatcherPriority.Normal);
return;
}
}
});
catch (Exception) { }
finally
{
this.CloseWindowSemaphoreSlim.Release();
}
}
}
else
{
Expand Down

0 comments on commit 70d433e

Please sign in to comment.