Jump to content
Tuts 4 You

WPF - AppDomain Issue


CodeExplorer

Recommended Posts

CodeExplorer

WPF - AppDomain Issue

I'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.html

The 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 reached

class Terminator : MarshalByRefObject

{

public Terminator()

{

System.Windows.Application.Current.Dispatcher.InvokeShutdown();

}

}

The result: an infinite loop while running Dispatcher.InvokeShutdown

I also noticed the presence of PresentationFontCache.exe

Any idea guys ?

Link to comment
CodeExplorer

// 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 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.

Link to comment

Can't you do:

Dispatcher.CurrentDispatcher.UnhandledException -= new DispatcherUnhandledExceptionEventHandler(p0.m000004);

AppDomain.CurrentDomain.UnhandledException -= new UnhandledExceptionEventHandler(p0.m000004);

Application.ThreadException -= new ThreadExceptionEventHandler(p0.m000004);

Link to comment
  • 4 weeks later...
CodeExplorer

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 :sweat:

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...