Skip to content

Commit 194a9ee

Browse files
yaira2hishitetsu
andauthored
Code Quality: Suppressed NullReferenceException caused by EnableRaisingEvents (#16157)
Co-authored-by: hishitetsu <[email protected]>
1 parent 0aea31f commit 194a9ee

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Files.App/ViewModels/ShellViewModel.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,11 @@ await Task.Factory.StartNew(() =>
19431943

19441944
private void WatchForWin32FolderChanges(string? folderPath)
19451945
{
1946-
if (Directory.Exists(folderPath))
1946+
if (!Directory.Exists(folderPath))
1947+
return;
1948+
1949+
// NOTE: Suppressed NullReferenceException caused by EnableRaisingEvents
1950+
SafetyExtensions.IgnoreExceptions(() =>
19471951
{
19481952
watcher = new FileSystemWatcher
19491953
{
@@ -1956,7 +1960,7 @@ private void WatchForWin32FolderChanges(string? folderPath)
19561960
watcher.Deleted += DirectoryWatcher_Changed;
19571961
watcher.Renamed += DirectoryWatcher_Changed;
19581962
watcher.EnableRaisingEvents = true;
1959-
}
1963+
}, App.Logger);
19601964
}
19611965

19621966
private async void DirectoryWatcher_Changed(object sender, FileSystemEventArgs e)

0 commit comments

Comments
 (0)