Await close event from non-ui thread

This commit is contained in:
Jack251970 2025-01-09 16:37:52 +08:00
parent 8aebf958aa
commit 122887e6a6
3 changed files with 15 additions and 7 deletions

View file

@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using Flow.Launcher.Infrastructure.Logger;
@ -64,13 +65,18 @@ namespace Flow.Launcher.Core
}
}
private new void Close()
public async Task CloseAsync()
{
if (!Application.Current.Dispatcher.CheckAccess())
{
Application.Current.Dispatcher.Invoke(Close);
await Application.Current.Dispatcher.InvokeAsync(Close);
}
Close();
}
private new void Close()
{
if (_isClosed)
{
return;

View file

@ -1,4 +1,6 @@
namespace Flow.Launcher.Plugin;
using System.Threading.Tasks;
namespace Flow.Launcher.Plugin;
/// <summary>
/// Interface for progress box
@ -16,5 +18,5 @@ public interface IProgressBoxEx
/// <summary>
/// Close progress box.
/// </summary>
public void Close();
public Task CloseAsync();
}

View file

@ -196,7 +196,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
if (downloadCancelled)
return;
else
prgBox?.Close();
await prgBox?.CloseAsync();
}
else
{
@ -217,7 +217,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
catch (HttpRequestException e)
{
// force close progress box
prgBox?.Close();
await prgBox?.CloseAsync();
// show error message
Context.API.ShowMsgError(
@ -230,7 +230,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
catch (Exception e)
{
// force close progress box
prgBox?.Close();
await prgBox?.CloseAsync();
// show error message
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),