mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-09-08 11:47:57 -04:00
fix: counting the visible books can no longer close Libation
Both UIs recount from async void event handlers, where a failure is not a faulted task anyone awaits but an unhandled exception. The count reads the file system, so a Books folder on a drive that was just unplugged was enough to end the session. See issue #1984. Co-authored-by: rmcrackan <rmcrackan@gmail.com>
This commit is contained in:
2 files changed
+30
-3
No files matched your search
@@ -199,8 +199,19 @@ partial class MainVM
|
||||
|
||||
private async Task setLiberatedVisibleMenuItemAsync()
|
||||
{
|
||||
var visible = ProductsDisplay.GetVisibleBookEntries();
|
||||
var libraryStats = await Task.Run(() => LibraryCommands.GetCounts(visible));
|
||||
await Dispatcher.UIThread.InvokeAsync(() => setVisibleNotLiberatedCount(libraryStats.PendingBooks));
|
||||
try
|
||||
{
|
||||
var visible = ProductsDisplay.GetVisibleBookEntries();
|
||||
var libraryStats = await Task.Run(() => LibraryCommands.GetCounts(visible));
|
||||
await Dispatcher.UIThread.InvokeAsync(() => setVisibleNotLiberatedCount(libraryStats.PendingBooks));
|
||||
}
|
||||
// Every caller is an async void event handler, where a failure is not a faulted task anyone awaits but
|
||||
// an unhandled exception that closes Libation. Counting these books reads the file system, which can
|
||||
// fail at any moment for reasons that have nothing to do with the app - a Books folder on a drive that
|
||||
// was just unplugged is enough. A stale number above a menu item is not worth the session.
|
||||
catch (Exception ex)
|
||||
{
|
||||
Serilog.Log.Logger.Error(ex, "Error counting the visible books which are not yet liberated");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,22 @@ public partial class Form1
|
||||
|
||||
private static DateTime lastVisibleCountUpdated;
|
||||
void setLiberatedVisibleMenuItem()
|
||||
{
|
||||
try
|
||||
{
|
||||
setLiberatedVisibleMenuItemCore();
|
||||
}
|
||||
// Both callers are async void event handlers, where a failure is not a faulted task anyone awaits but
|
||||
// an unhandled exception that closes Libation. Counting these books reads the file system, which can
|
||||
// fail at any moment for reasons that have nothing to do with the app - a Books folder on a drive that
|
||||
// was just unplugged is enough. A stale number above a menu item is not worth the session.
|
||||
catch (Exception ex)
|
||||
{
|
||||
Serilog.Log.Logger.Error(ex, "Error counting the visible books which are not yet liberated");
|
||||
}
|
||||
}
|
||||
|
||||
private void setLiberatedVisibleMenuItemCore()
|
||||
{
|
||||
//Assume that all calls to update arrive in order,
|
||||
//Only display results of the latest book count.
|
||||
|
||||
Reference in new issue
Block a user