Parcourir la source

2004-03-21 Gonzalo Paniagua Javier <[email protected]>

	* ThreadAbortException.cs: use same HResult as MS.
	* Timer.cs: abort the running thread when disposing the Timer. This
	fixes NullRefs when finishing xsp.

svn path=/trunk/mcs/; revision=24386
Gonzalo Paniagua Javier il y a 22 ans
Parent
commit
271bb68c4e

+ 6 - 0
mcs/class/corlib/System.Threading/ChangeLog

@@ -1,3 +1,9 @@
+2004-03-21  Gonzalo Paniagua Javier <[email protected]>
+
+	* ThreadAbortException.cs: use same HResult as MS.
+	* Timer.cs: abort the running thread when disposing the Timer. This
+	fixes NullRefs when finishing xsp.
+
 2004-03-15  Gonzalo Paniagua Javier <[email protected]>
 
 	* NativeOverlapped.cs: added 2 new internal fields.

+ 4 - 1
mcs/class/corlib/System.Threading/ThreadAbortException.cs

@@ -14,7 +14,10 @@ namespace System.Threading
 	[Serializable]
 	public sealed class ThreadAbortException : SystemException
 	{
-		private ThreadAbortException () : base ("Thread was being aborted") {}
+		private ThreadAbortException () : base ("Thread was being aborted")
+		{
+			HResult = unchecked ((int) 0x80131530);
+		}
 
 		public object ExceptionState {
 			get {

+ 12 - 27
mcs/class/corlib/System.Threading/Timer.cs

@@ -6,6 +6,7 @@
 // 	Gonzalo Paniagua Javier ([email protected])
 //
 // (C) 2001, 2002 Ximian, Inc.  http://www.ximian.com
+// (C) 2004 Novell, Inc. http://www.novell.com
 //
 
 
@@ -13,7 +14,7 @@ namespace System.Threading
 {
 	public sealed class Timer : MarshalByRefObject, IDisposable
 	{
-		sealed class Runner : MarshalByRefObject, IDisposable
+		sealed class Runner : MarshalByRefObject
 		{
 			ManualResetEvent wait;
 			AutoResetEvent start_event;
@@ -102,34 +103,11 @@ namespace System.Threading
 					}
 				}
 			}
-
-			public void Dispose ()
-			{
-				Dispose (true);
-			}
-
-			void Dispose (bool disposing)
-			{
-				disposed = true;
-				if (disposing) {
-					if (wait != null) {
-						wait.Set ();
-						Thread.Sleep (100);
-						((IDisposable) wait).Dispose ();
-						wait = null;
-					}
-					GC.SuppressFinalize (this);
-				}
-			}
-
-			~Runner ()
-			{
-				Dispose (false);
-			}
 		}
 
 		Runner runner;
 		AutoResetEvent start_event;
+		Thread t;
 
 		public Timer (TimerCallback callback, object state, int dueTime, int period)
 		{
@@ -169,7 +147,7 @@ namespace System.Threading
 			start_event = new AutoResetEvent (false);
 			runner = new Runner (callback, state, start_event);
 			Change (dueTime, period);
-			Thread t = new Thread (new ThreadStart (runner.Start));
+			t = new Thread (new ThreadStart (runner.Start));
 			t.IsBackground = true;
 			t.Start ();
 		}
@@ -220,7 +198,10 @@ namespace System.Threading
 
 		public void Dispose ()
 		{
-			runner.Dispose ();
+			if (t != null && t.IsAlive) {
+				t.Abort ();
+				t = null;
+			}
 			runner = null;
 			GC.SuppressFinalize (this);
 		}
@@ -234,6 +215,10 @@ namespace System.Threading
 
 		~Timer ()
 		{
+			if (t != null && t.IsAlive) {
+				t.Abort ();
+				t = null;
+			}
 			runner = null;
 		}
 	}