簡體   English   中英

會話結束事件無效

[英]Session Ending event not working

我想讓用戶在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。

我嘗試了你的代碼示例但沒有成功...但是我將它放入我的主窗口,導致應用程序關閉,MessageBox無限期地顯示,直到我點擊關閉。 這有用嗎?

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

        base.OnClosing(e);
    }

嘗試覆蓋已經存在的事件處理程序。

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

 public partial class App : Application { protected override void OnSessionEnding(SessionEndingCancelEventArgs e) { // Always call method in base class, so that the event gets raised. base.OnSessionEnding(e); // Place your own SessionEnding logic here } } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM