Non-null disposed BlockingCollection can throw exception

This commit is contained in:
Robert McRackan committed 2022-06-21 21:08:49 -04:00
1 parent eff2634b32
commit ba722487d8
1 file changed
+7 -2
+7 -2
View File
@@ -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();