1
我需要在關機/註銷時執行代碼。當這些操作中的任何一個都會使代碼爲0xe0434352的應用程序出錯。什麼即時做錯了?WPF和WndProc掛起.NET異常
這是我的代碼:
private void Window_SourceInitialized(object sender, EventArgs e)
{
IntPtr windowHandle = (new WindowInteropHelper(this)).Handle;
HwndSource src = HwndSource.FromHwnd(windowHandle);
src.AddHook(new HwndSourceHook(WndProc));
}
private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == 0x0011)
{
EventLog.WriteEntry("WPF1", "finally!");
//my code
}
return IntPtr.Zero;
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
IntPtr windowHandle = (new WindowInteropHelper(this)).Handle;
HwndSource src = HwndSource.FromHwnd(windowHandle);
src.RemoveHook(new HwndSourceHook(this.WndProc));
}
異常錯誤:http://pastebin.com/gaX0ekaP