Skip to content

Commit

Permalink
Code Quality: Suppressed NullReferenceException caused by EnableRaisi…
Browse files Browse the repository at this point in the history
…ngEvents (files-community#16157)

Co-authored-by: hishitetsu <[email protected]>
  • Loading branch information
yaira2 and hishitetsu authored Sep 9, 2024
1 parent 0aea31f commit 194a9ee
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Files.App/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1943,7 +1943,11 @@ await Task.Factory.StartNew(() =>

private void WatchForWin32FolderChanges(string? folderPath)
{
if (Directory.Exists(folderPath))
if (!Directory.Exists(folderPath))
return;

// NOTE: Suppressed NullReferenceException caused by EnableRaisingEvents
SafetyExtensions.IgnoreExceptions(() =>
{
watcher = new FileSystemWatcher
{
Expand All @@ -1956,7 +1960,7 @@ private void WatchForWin32FolderChanges(string? folderPath)
watcher.Deleted += DirectoryWatcher_Changed;
watcher.Renamed += DirectoryWatcher_Changed;
watcher.EnableRaisingEvents = true;
}
}, App.Logger);
}

private async void DirectoryWatcher_Changed(object sender, FileSystemEventArgs e)
Expand Down

0 comments on commit 194a9ee

Please sign in to comment.