CodeExplorer Posted April 12, 2011 Posted April 12, 2011 WPF - AppDomain IssueI've readed these articles:/>http://social.msdn.microsoft.com/Forums/en/wpf/thread/eb9ef4ce-dd16-45b9-a925-b7abccec9b51/>http://www.joeseymour.net/2009/01/wpf-showdown-appdomaincurrentdomainsett.html/>http://blogs.msdn.com/b/changov/archive/2009/10/26/hosting-wpf-ui-cross-thread-and-cross-process.aspx/>http://www.infosysblogs.com/microsoft/2008/10/working_with_application_domai_1.htmlThe program which I load MI.sappDomain is Reflector and yep he use WPF.MessageBox.Show("1");MI.sappDomain.CreateInstanceAndUnwrap("Simple_MSIL_Decryptor", "Simple_MSIL_Decryptor.Terminator");MessageBox.Show("2"); // never reachedclass Terminator : MarshalByRefObject { public Terminator() { System.Windows.Application.Current.Dispatcher.InvokeShutdown(); } }The result: an infinite loop while running Dispatcher.InvokeShutdownI also noticed the presence of PresentationFontCache.exeAny idea guys ?
CodeExplorer Posted April 14, 2011 Author Posted April 14, 2011 // on the new created domain we invoke ShutdownThread cthread = Thread.CurrentThread;Assembly wbaseasm = Assembly.Load("WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35");if (wbaseasm!=null){Type type = wbaseasm.GetType("System.Windows.Threading.Dispatcher");if (type!=null){MethodBase mb = type.GetMethod("FromThread", new Type[] {typeof(Thread)});if (mb!=null){object cdispatcher = mb.Invoke(null, new object[] {cthread});if (cdispatcher!=null){MethodInfo shutdownimpl = type.GetMethod("InvokeShutdown",BindingFlags.Instance | BindingFlags.Public);shutdownimpl.Invoke(cdispatcher, new object[] {});}}}}I've use MethodBase invoke so you won't have to compile to Framework 3.5;I still can't unload the new created AppDomain the problems actualy comes because of SA exception craps:Dispatcher.CurrentDispatcher.UnhandledException += new DispatcherUnhandledExceptionEventHandler(p0.m000004);AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(p0.m000004);Application.ThreadException += new ThreadExceptionEventHandler(p0.m000004);The problem is that exception handler are called : damn.
phoenix Posted April 17, 2011 Posted April 17, 2011 Can't you do:Dispatcher.CurrentDispatcher.UnhandledException -= new DispatcherUnhandledExceptionEventHandler(p0.m000004);AppDomain.CurrentDomain.UnhandledException -= new UnhandledExceptionEventHandler(p0.m000004);Application.ThreadException -= new ThreadExceptionEventHandler(p0.m000004);
CodeExplorer Posted May 13, 2011 Author Posted May 13, 2011 I fixed that problem! This code is enough: // on the new created domain we invoke Shutdown Thread cthread = Thread.CurrentThread; Assembly wbaseasm = Assembly.Load("WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"); if (wbaseasm!=null) { Type type = wbaseasm.GetType("System.Windows.Threading.Dispatcher"); if (type!=null) { MethodBase mb = type.GetMethod("FromThread", new Type[] {typeof(Thread)}); if (mb!=null) { object cdispatcher = mb.Invoke(null, new object[] {cthread}); if (cdispatcher!=null) { MethodInfo shutdownimpl = type.GetMethod("InvokeShutdown", BindingFlags.Instance | BindingFlags.Public); shutdownimpl.Invoke(cdispatcher, new object[] {}); } } } } I've thinked that is about some unterminated thread but infact was about me closing threads using TerminateThread - when I shouldn't do this
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now