From 532605f53397f966b9b3dfff4e3f6452956d22fa Mon Sep 17 00:00:00 2001 From: Alexis Christoforides Date: Mon, 8 Jul 2019 13:45:49 -0400 Subject: [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 --- mcs/class/System/System.IO/FileSystemWatcher.cs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'mcs/class/System/System.IO/FileSystemWatcher.cs') 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 (); } -- cgit v1.2.3