diff options
author | Alexis Christoforides <alexis@thenull.net> | 2019-07-08 20:45:49 +0300 |
---|---|---|
committer | Alexis Christoforides <alexis@thenull.net> | 2019-07-15 23:25:32 +0300 |
commit | 532605f53397f966b9b3dfff4e3f6452956d22fa (patch) | |
tree | abb9d5537c875f5b2e78ee67376a0cc232010536 /mcs/class/System/System.IO | |
parent | 4b6f49bb064dd3a717daddc7ed9dec3659dfcc08 (diff) |
[System] Keep events from firing from a disposed 'DefaultWatcher' FileSystemWatcher
Fixes https://github.com/mono/mono/issues/8747
Also try to stop other implementations from dispatching events past Dispose(), without guaranteeing it
Diffstat (limited to 'mcs/class/System/System.IO')
-rw-r--r-- | mcs/class/System/System.IO/DefaultWatcher.cs | 9 | ||||
-rw-r--r-- | mcs/class/System/System.IO/FileSystemWatcher.cs | 6 |
2 files changed, 12 insertions, 3 deletions
diff --git a/mcs/class/System/System.IO/DefaultWatcher.cs b/mcs/class/System/System.IO/DefaultWatcher.cs index 19c30b890e7..6bc6f9feca5 100644 --- a/mcs/class/System/System.IO/DefaultWatcher.cs +++ b/mcs/class/System/System.IO/DefaultWatcher.cs @@ -128,8 +128,10 @@ namespace System.IO { lock (watches) { data = (DefaultWatcherData) watches [fsw]; if (data != null) { - data.Enabled = false; - data.DisabledTime = DateTime.UtcNow; + lock (data.FilesLock) { + data.Enabled = false; + data.DisabledTime = DateTime.UtcNow; + } } } } @@ -221,7 +223,8 @@ namespace System.IO { } lock (data.FilesLock) { - IterateAndModifyFilesData (data, directory, dispatch, files); + if (data.Enabled) + IterateAndModifyFilesData (data, directory, dispatch, files); } } diff --git a/mcs/class/System/System.IO/FileSystemWatcher.cs b/mcs/class/System/System.IO/FileSystemWatcher.cs index adfd9cfc336..b7ad29d0c08 100644 --- a/mcs/class/System/System.IO/FileSystemWatcher.cs +++ b/mcs/class/System/System.IO/FileSystemWatcher.cs @@ -420,6 +420,8 @@ namespace System.IO { } private void RaiseEvent (Delegate ev, EventArgs arg, EventType evtype) { + if (disposed) + return; if (ev == null) return; @@ -497,11 +499,15 @@ namespace System.IO { internal void DispatchErrorEvents (ErrorEventArgs args) { + if (disposed) + return; OnError (args); } internal void DispatchEvents (FileAction act, string filename, ref RenamedEventArgs renamed) { + if (disposed) + return; if (waiting) { lastData = new WaitForChangedResult (); } |