Просмотр исходного кода

2006-11-07 Robert Jordan <[email protected]>

	* WaitHandle.cs: Don't assume Assembly.GetEntryAssembly () != null.
	Fixes bug #79859.


svn path=/trunk/mcs/; revision=67496
Robert Jordan 19 лет назад
Родитель
Сommit
26a197b7c1

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

@@ -1,3 +1,8 @@
+2006-11-07  Robert Jordan  <[email protected]>
+
+	* WaitHandle.cs: Don't assume Assembly.GetEntryAssembly () != null.
+	Fixes bug #79859.
+
 2006-11-02  Dick Porter  <[email protected]>
 
 	* Thread.cs: Use the new Interrupt and SpinWait icalls.

+ 18 - 3
mcs/class/corlib/System.Threading/WaitHandle.cs

@@ -50,9 +50,7 @@ namespace System.Threading
 			if (length > 64)
 				throw new NotSupportedException ("Too many handles");
 
-			if (waitAll && length > 1 &&
-			    (Thread.CurrentThread.ApartmentState == ApartmentState.STA ||
-			     Assembly.GetEntryAssembly ().EntryPoint.GetCustomAttributes (typeof (STAThreadAttribute), false).Length == 1))
+			if (waitAll && length > 1 && IsSTAThread)
 				throw new NotSupportedException ("WaitAll for multiple handles is not allowed on an STA thread.");
 			
 			foreach (WaitHandle w in handles) {
@@ -63,6 +61,23 @@ namespace System.Threading
 					throw new ArgumentException ("null element found", "waitHandle");
 			}
 		}
+
+		static bool IsSTAThread {
+			get {
+				bool isSTA = Thread.CurrentThread.ApartmentState ==
+					ApartmentState.STA;
+
+				// FIXME: remove this check after Thread.ApartmentState
+				// has been properly implemented.
+				if (!isSTA) {
+					Assembly asm = Assembly.GetEntryAssembly ();
+					if (asm != null)
+						isSTA = asm.EntryPoint.GetCustomAttributes (typeof (STAThreadAttribute), false).Length > 0;
+				}
+
+				return isSTA;
+			}
+		}
 		
 		public static bool WaitAll(WaitHandle[] waitHandles)
 		{