From ba722487d8c7be977d8246e152131e9c1d829b2f Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Tue, 21 Jun 2022 21:08:49 -0400 Subject: [PATCH] Non-null disposed BlockingCollection can throw exception --- Source/FileManager/BackgroundFileSystem.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/FileManager/BackgroundFileSystem.cs b/Source/FileManager/BackgroundFileSystem.cs index 4f68003d..f3f9a747 100644 --- a/Source/FileManager/BackgroundFileSystem.cs +++ b/Source/FileManager/BackgroundFileSystem.cs @@ -79,8 +79,13 @@ namespace FileManager //Stop raising events fileSystemWatcher?.Dispose(); - //Calling CompleteAdding() will cause background scanner to terminate. - directoryChangesEvents?.CompleteAdding(); + try + { + //Calling CompleteAdding() will cause background scanner to terminate. + directoryChangesEvents?.CompleteAdding(); + } + // if directoryChangesEvents is non-null and isDisposed, this exception is thrown. there's no other way to check >:( + catch (ObjectDisposedException) { } //Wait for background scanner to terminate before reinitializing. backgroundScanner?.Wait();