会话结束事件无效

时间:2013-09-29 15:00:02

标签: c# .net wpf windows-7

我希望让用户在Windows关闭或注销时决定是否要在我的应用中执行最后一次请求。所以我正在使用“SessionEnding”活动。

以下代码已触发但无效。这是最简单的例子:

public App()
{
        this.SessionEnding += App_SessionEnding;
}

void App_SessionEnding(object sender, SessionEndingCancelEventArgs e)
{
        e.Cancel = true;
}

我担心我之前在计算机中使用了一个提升程序(比如CCleaner),并且它以某种方式停用了这个事件。 = O

当我向事件添加MessageBox,并且我请求注销我的计算机时,会出现MessageBox,但我没有时间点击某处,因为1秒钟后系统会注销。系统似乎没有等待我的申请。

Obs:我使用的是Windows 7。

2 个答案:

答案 0 :(得分:1)

我尝试了一些代码示例但没有成功...但是我将它放入我的主窗口,导致应用程序关闭,MessageBox无限期地显示,直到我点击关闭。这有用吗?

protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
    {
        MessageBox.Show("Blah", "Blah", MessageBoxButton.OK);

        base.OnClosing(e);
    }

答案 1 :(得分:0)

尝试覆盖已存在的事件处理程序。

https://wpf.2000things.com/2011/01/25/197-override-application-class-methods-for-standard-events/

IMPORTANCE_DEFAULT
相关问题