Improve my previous change a bit.
authorAlex Rønne Petersen <alexrp@xamarin.com>
Sat, 9 Nov 2013 01:52:20 +0000 (02:52 +0100)
committerAlex Rønne Petersen <alexrp@xamarin.com>
Sat, 9 Nov 2013 01:52:20 +0000 (02:52 +0100)
Checking the `disposing` argument is cleaner.

mcs/class/System/System.Timers/Timer.cs

index ed3aee94b96a4b1dac90922ab80d6f9cca1556e0..28a7011bb545c2cabf6c422bb896c3212c08c011 100644 (file)
@@ -159,9 +159,11 @@ namespace System.Timers
 
                protected override void Dispose (bool disposing)
                {
-                       // If _lock is null, it means we're finalizing,
-                       // in which case everything has been nulled anyway.
-                       if (_lock != null)
+                       // If we're disposing explicitly, clear all
+                       // fields. If not, all fields will have been
+                       // nulled by the GC during finalization, so
+                       // trying to lock on _lock will blow up.
+                       if (disposing)
                                Close ();
 
                        base.Dispose (disposing);