#1811 - fix UI threading

This commit is contained in:
rmcrackan
2026-05-15 12:02:23 -04:00
parent 776cd5215f
commit 55b45ae45d
2 changed files with 16 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ using ApplicationServices;
using AudibleUtilities;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Threading;
using LibationFileManager;
using LibationUiBase;
using LibationUiBase.Forms;
@@ -71,8 +72,8 @@ public partial class MainVM
AutoScanChecked = Configuration.Instance.AutoScan;
setyNumScanningAccounts(0);
LibraryCommands.ScanBegin += (_, accountsLength) => setyNumScanningAccounts(accountsLength);
LibraryCommands.ScanEnd += (_, newCount) => setyNumScanningAccounts(0);
LibraryCommands.ScanBegin += (_, accountsLength) => Dispatcher.UIThread.Post(() => setyNumScanningAccounts(accountsLength));
LibraryCommands.ScanEnd += (_, _) => Dispatcher.UIThread.Post(() => setyNumScanningAccounts(0));
if (!Design.IsDesignMode)
RemoveButtonsVisible = false;

View File

@@ -13,6 +13,13 @@ public partial class Form1
private void LibraryCommands_ScanBegin(object? sender, int accountsLength)
{
// ImportAccountAsync (incl. auto-scan) runs on a worker thread; ToolStrip must be touched on the UI thread.
if (InvokeRequired)
{
BeginInvoke(LibraryCommands_ScanBegin, sender, accountsLength);
return;
}
removeLibraryBooksToolStripMenuItem.Enabled = false;
removeAllAccountsToolStripMenuItem.Enabled = false;
removeSomeAccountsToolStripMenuItem.Enabled = false;
@@ -30,6 +37,12 @@ public partial class Form1
private void LibraryCommands_ScanEnd(object? sender, int newCount)
{
if (InvokeRequired)
{
BeginInvoke(LibraryCommands_ScanEnd, sender, newCount);
return;
}
removeLibraryBooksToolStripMenuItem.Enabled = true;
removeAllAccountsToolStripMenuItem.Enabled = true;
removeSomeAccountsToolStripMenuItem.Enabled = true;