Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c1227b

Browse files
Fix NullReferenceException
Fix NullReferenceException in FileSystemWatcher on Windows if two threads try and dispose the instance at the same time.
1 parent bc2bd2b commit 8c1227b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Win32.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private void StopRaisingEvents()
105105
// increased, such that the disposal operation won't take effect and close the handle
106106
// until that P/Invoke returns; if during that time the FSW is restarted, the IsHandleInvalid
107107
// check will see a valid handle, unless we also null it out.
108-
_directoryHandle.Dispose();
108+
_directoryHandle?.Dispose();
109109
_directoryHandle = null;
110110
}
111111

0 commit comments

Comments
 (0)