+2009-06-10 Sebastien Pouliot <sebastien@ximian.com>
+
+ * Thread.cs: Refactor calling Moonlight's OnUnhandledException to
+ make sur the delegate it not called from a [SecuritySafeCritical]
+ caller.
+ * ThreadPool.cs: Reuse the above code for QueueUserWorkItem.
+ Original patch from Alan McGovern
+
2009-06-10 Marek Safar <marek.safar@gmail.com>
* LockRecursionException.cs: New file.
using System.Runtime.InteropServices;
using System.IO;
using System.Collections;
+using System.Reflection;
using System.Security;
#if NET_2_0
((ParameterizedThreadStart) threadstart) (start_obj);
}
} catch (Exception ex) {
- try {
- try {
- var assembly = System.Reflection.Assembly.Load ("System.Windows, Version=2.0.5.0, Culture=Neutral, PublicKeyToken=7cec85d7bea7798e");
- var application = assembly.GetType ("System.Windows.Application");
- var method = application.GetMethod ("OnUnhandledException", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
- method.Invoke (null, new object [] {null, ex});
- } catch (Exception e) {
- Console.WriteLine ("Unexpected exception while trying to report unhandled application exception: {0}", e);
- }
- } catch {
+ MoonlightUnhandledException (ex);
+ }
+ }
+
+ static MethodInfo moonlight_unhandled_exception = null;
+
+ static internal void MoonlightUnhandledException (Exception e)
+ {
+ try {
+ if (moonlight_unhandled_exception == null) {
+ var assembly = System.Reflection.Assembly.Load ("System.Windows, Version=2.0.5.0, Culture=Neutral, PublicKeyToken=7cec85d7bea7798e");
+ var application = assembly.GetType ("System.Windows.Application");
+ moonlight_unhandled_exception = application.GetMethod ("OnUnhandledException",
+ System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
}
+ moonlight_unhandled_exception.Invoke (null, new object [] { null, e });
+ }
+ catch {
+ Console.WriteLine ("Unexpected exception while trying to report unhandled application exception: {0}", e);
}
}
#endif
public static bool QueueUserWorkItem (WaitCallback callBack)
{
- IAsyncResult ar = callBack.BeginInvoke (null, null, null);
- if (ar == null)
- return false;
- return true;
+ return QueueUserWorkItem (callBack, null);
}
public static bool QueueUserWorkItem (WaitCallback callBack, object state)
{
+ callBack = MoonlightHandler (callBack);
IAsyncResult ar = callBack.BeginInvoke (state, null, null);
if (ar == null)
return false;
{
throw new NotImplementedException ();
}
+
+ static WaitCallback MoonlightHandler (WaitCallback callback)
+ {
+#if NET_2_1
+ return delegate (object o) {
+ try {
+ callback (o);
+ }
+ catch (Exception ex) {
+ Thread.MoonlightUnhandledException (ex);
+ }
+ };
+#else
+ return callback;
+#endif
+ }
}
}