Re: Relationship between Application.Exit() and AppDomain



Willy Denoyette [MVP] wrote:

Application.Exit() is a Forms API,

That is true.

so A.E makes no sense in WPF.

That may be strictly true, but try this on for size:

---8<---
using System;
using System.Windows;
using System.Threading;
using System.Runtime.InteropServices;
using System.Windows.Controls;

public class App
{
[DllImport("user32.dll")]
static extern void PostQuitMessage(int nExitCode);

static Button MakeQuitButton()
{
Button result = new Button();
result.Content = "Quit";
result.Click += (s,e) => PostQuitMessage(0);
return result;
}

[STAThread]
static void Main()
{
new Application().Run(new Window()
{
Content = MakeQuitButton()
});
}
}
--->8---

WPF does not run a message loop

This is empirically false:

---8<---
ntkrnlpa.exe!KiSwapContext+0x2f
ntkrnlpa.exe!KiSwapThread+0x8a
ntkrnlpa.exe!KeWaitForSingleObject+0x1c2
ntkrnlpa.exe!KiSuspendThread+0x18
ntkrnlpa.exe!KiDeliverApc+0x124
ntkrnlpa.exe!KiSwapThread+0xa8
ntkrnlpa.exe!KeWaitForSingleObject+0x1c2
win32k.sys!xxxSleepThread+0x192
win32k.sys!xxxRealInternalGetMessage+0x418
win32k.sys!NtUserGetMessage+0x27
ntkrnlpa.exe!KiFastCallEntry+0xfc
ntdll.dll!KiFastSystemCallRet
USER32.dll!NtUserGetMessage+0xc
WindowsBase.ni.dll+0x5e623
WindowsBase.ni.dll!ResetValue+0xd
WindowsBase.ni.dll!get_SourceProperty+0x1
WindowsBase.ni.dll!.ctor+0xe
WindowsBase.ni.dll!ConvertToString+0x21
WindowsBase.ni.dll!ConvertToString+0x2
PresentationFramework.ni.dll!AlignContent+0x7b
mscorwks.dll!CallDescrWorkerWithHandler+0xa3
mscorwks.dll!MethodDesc::CallDescr+0x19c
mscorwks.dll!MethodDesc::CallTargetWorker+0x1f
mscorwks.dll!MethodDescCallSite::Call_RetArgSlot+0x18
mscorwks.dll!ClassLoader::RunMain+0x263
mscorwks.dll!Assembly::ExecuteMainMethod+0xa6
mscorwks.dll!SystemDomain::ExecuteMainMethod+0x43f
mscorwks.dll!ExecuteEXE+0x59
mscorwks.dll!_CorExeMain+0x15c
mscoree.dll!_CorExeMain+0x2c
KERNEL32.dll!BaseProcessStart+0x23
--->8---

NtUserGetMessage is there, clear as day.

-- Barry

--
http://barrkel.blogspot.com/
.


Loading