public static bool MessageHandler(ref Message m)
        {
            if (m.Msg == WM_ENDSESSION || (m.Msg == WM_QUERYENDSESSION && ShutdownInitiated))
            {
                m.Result = new IntPtr(ENDSESSION_CLOSEAPP);
                return(true);
            }
            else if (m.Msg == WM_QUERYENDSESSION)
            {
                //system getting ready to shut down
                //individual *forms* receive this message, so we must protect against a race condition
                using (var shutdownMutex = new ScopedMutex(_appName + "{EA433526-9724-43FD-B175-6EA7BA7517A4}"))
                {
                    if (ShutdownInitiated)
                    {
                        m.Result = new IntPtr(ENDSESSION_CLOSEAPP);
                        return(true);
                    }

                    ShutdownInitiated = true;
                    var recoveryMan = new RecoveryManager();
                    recoveryMan.CreateRecoveryData(recoveryMan.UnsafeShutdownPath);
                    ShutdownDumpComplete.Set();
                    m.Result = new IntPtr(ENDSESSION_CLOSEAPP);
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        protected override void WndProc(ref Message m)
        {
            if (RecoveryManager.MessageHandler(ref m))
            {
                return;
            }

            if (m.Msg == Win32.WM_COPYDATA)
            {
                var path = Win32.ReceiveWindowMessage(m);
                OpenNew(path, false);
            }

            base.WndProc(ref m);
        }