Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

WPF - AppDomain Issue

Featured Replies

Posted

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 ?

  • Author

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

Can't you do:

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

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

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

  • 4 weeks later...
  • Author

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:

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.