Do library scan on background thread

This commit is contained in:
MBucari 2025-07-22 00:20:16 -06:00
parent 1fdcea929f
commit 890747a902
4 changed files with 5 additions and 8 deletions

View File

@ -202,7 +202,7 @@ namespace LibationAvalonia.ViewModels
{ {
try try
{ {
var (totalProcessed, newAdded) = await LibraryCommands.ImportAccountAsync(accounts); var (totalProcessed, newAdded) = await Task.Run(() => LibraryCommands.ImportAccountAsync(accounts));
// this is here instead of ScanEnd so that the following is only possible when it's user-initiated, not automatic loop // this is here instead of ScanEnd so that the following is only possible when it's user-initiated, not automatic loop
if (Configuration.Instance.ShowImportedStats && newAdded > 0) if (Configuration.Instance.ShowImportedStats && newAdded > 0)

View File

@ -5,6 +5,7 @@ using LibationFileManager;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
#nullable enable #nullable enable
namespace LibationAvalonia.ViewModels namespace LibationAvalonia.ViewModels
@ -27,7 +28,7 @@ namespace LibationAvalonia.ViewModels
// in autoScan, new books SHALL NOT show dialog // in autoScan, new books SHALL NOT show dialog
try try
{ {
await LibraryCommands.ImportAccountAsync(accounts); await Task.Run(() => LibraryCommands.ImportAccountAsync(accounts));
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ {

View File

@ -32,11 +32,7 @@ namespace LibationWinForms
// in autoScan, new books SHALL NOT show dialog // in autoScan, new books SHALL NOT show dialog
try try
{ {
Task importAsync() => LibraryCommands.ImportAccountAsync(accounts); await Task.Run(() => LibraryCommands.ImportAccountAsync(accounts));
if (InvokeRequired)
await Invoke(importAsync);
else
await importAsync();
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ {

View File

@ -74,7 +74,7 @@ namespace LibationWinForms
{ {
try try
{ {
var (totalProcessed, newAdded) = await LibraryCommands.ImportAccountAsync(accounts); var (totalProcessed, newAdded) = await Task.Run(() => LibraryCommands.ImportAccountAsync(accounts));
// this is here instead of ScanEnd so that the following is only possible when it's user-initiated, not automatic loop // this is here instead of ScanEnd so that the following is only possible when it's user-initiated, not automatic loop
if (Configuration.Instance.ShowImportedStats && newAdded > 0) if (Configuration.Instance.ShowImportedStats && newAdded > 0)