From 12abbb79b18f2bae4e6e73b725bcd2909e9ee652 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Fri, 6 May 2022 16:00:37 -0400 Subject: [PATCH] Don't allow multiple simultaneous imports --- AppScaffolding/AppScaffolding.csproj | 2 +- ApplicationServices/LibraryCommands.cs | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/AppScaffolding/AppScaffolding.csproj b/AppScaffolding/AppScaffolding.csproj index 9df8e828..04cc9388 100644 --- a/AppScaffolding/AppScaffolding.csproj +++ b/AppScaffolding/AppScaffolding.csproj @@ -3,7 +3,7 @@ net6.0-windows - 7.1.0.1 + 7.1.1.1 diff --git a/ApplicationServices/LibraryCommands.cs b/ApplicationServices/LibraryCommands.cs index d966d8d9..3bbf93c5 100644 --- a/ApplicationServices/LibraryCommands.cs +++ b/ApplicationServices/LibraryCommands.cs @@ -15,7 +15,19 @@ namespace ApplicationServices { public static class LibraryCommands { - public static async Task> FindInactiveBooks(Func> apiExtendedfunc, List existingLibrary, params Account[] accounts) + public static event EventHandler ScanBegin; + public static event EventHandler ScanEnd; + + public static bool Scanning { get; private set; } + private static object _lock { get; } = new(); + + static LibraryCommands() + { + ScanBegin += (_, __) => Scanning = true; + ScanEnd += (_, __) => Scanning = false; + } + + public static async Task> FindInactiveBooks(Func> apiExtendedfunc, List existingLibrary, params Account[] accounts) { logRestart(); @@ -72,8 +84,6 @@ namespace ApplicationServices } } - public static event EventHandler ScanBegin; - public static event EventHandler ScanEnd; #region FULL LIBRARY scan and import public static async Task<(int totalCount, int newCount)> ImportAccountAsync(Func> apiExtendedfunc, params Account[] accounts) { @@ -84,7 +94,12 @@ namespace ApplicationServices try { - ScanBegin?.Invoke(null, accounts.Length); + lock (_lock) + { + if (Scanning) + return (0, 0); + ScanBegin?.Invoke(null, accounts.Length); + } logTime($"pre {nameof(scanAccountsAsync)} all"); var importItems = await scanAccountsAsync(apiExtendedfunc, accounts, LibraryOptions.ResponseGroupOptions.ALL_OPTIONS);