This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +6
-2
lines changed
src/System.IO.FileSystem.Watcher Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -75,8 +75,13 @@ private void StopRaisingEvents()
75
75
// This operation doesn't need to be atomic because the API will deal with a closed
76
76
// handle appropriately. If we get here while asynchronously waiting on a change notification,
77
77
// closing the directory handle should cause ReadDirectoryChangesCallback be be called,
78
- // cleaning up the operation.
78
+ // cleaning up the operation. Note that it's critical to also null out the handle. If the
79
+ // handle is currently in use in a P/Invoke, it will have its reference count temporarily
80
+ // increased, such that the disposal operation won't take effect and close the handle
81
+ // until that P/Invoke returns; if during that time the FSW is restarted, the IsHandleInvalid
82
+ // check will see a valid handle, unless we also null it out.
79
83
_directoryHandle . Dispose ( ) ;
84
+ _directoryHandle = null ;
80
85
81
86
// Set enabled to false
82
87
_enabled = false ;
Original file line number Diff line number Diff line change @@ -146,7 +146,6 @@ public static void FileSystemWatcher_Changed_FileDataChange()
146
146
}
147
147
}
148
148
149
- [ ActiveIssue ( 2740 ) ]
150
149
[ Theory ]
151
150
[ InlineData ( true ) ]
152
151
[ InlineData ( false ) ]
You can’t perform that action at this time.
0 commit comments