Application.SessionEnding 이벤트

정의

사용자가 로그오프하거나 운영 체제를 종료하여 Windows 세션을 끝낼 때 발생합니다.

public:
 event System::Windows::SessionEndingCancelEventHandler ^ SessionEnding;
public event System.Windows.SessionEndingCancelEventHandler SessionEnding;
member this.SessionEnding : System.Windows.SessionEndingCancelEventHandler 
Public Custom Event SessionEnding As SessionEndingCancelEventHandler 

이벤트 유형

예제

다음 예제에서는 이벤트를 처리 SessionEnding 하 고 사용자가 취소할 수 있도록 하는 방법을 보여 줍니다.

<Application 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="SDKSample.App"
    StartupUri="MainWindow.xaml"
    SessionEnding="App_SessionEnding" />
using System.Windows;

namespace SDKSample
{
    public partial class App : Application
    {
        void App_SessionEnding(object sender, SessionEndingCancelEventArgs e)
        {
            // Ask the user if they want to allow the session to end
            string msg = string.Format("{0}. End session?", e.ReasonSessionEnding);
            MessageBoxResult result = MessageBox.Show(msg, "Session Ending", MessageBoxButton.YesNo);

            // End session, if specified
            if (result == MessageBoxResult.No)
            {
                e.Cancel = true;
            }
        }
    }
}

Imports System.Windows

Namespace SDKSample
    Partial Public Class App
        Inherits Application
        Private Sub App_SessionEnding(ByVal sender As Object, ByVal e As SessionEndingCancelEventArgs)
            ' Ask the user if they want to allow the session to end
            Dim msg As String = String.Format("{0}. End session?", e.ReasonSessionEnding)
            Dim result As MessageBoxResult = MessageBox.Show(msg, "Session Ending", MessageBoxButton.YesNo)

            ' End session, if specified
            If result = MessageBoxResult.No Then
                e.Cancel = True
            End If
        End Sub
    End Class
End Namespace

설명

기본적으로 애플리케이션이 종료 될 때 사용자가 로그 오프 하거나 종료 하는 경우 발생 하는 Windows 세션이 종료 됩니다. 이 경우 Windows는 각 열린 애플리케이션을 종료를 요청 합니다. 그러나 있기 애플리케이션이이 경우 종료 준비가 되어 있지 않을 수 있습니다. 예를 들어, 애플리케이션에 일관 되지 않은 상태의 또는 장기 실행 작업 중에 데이터 있을 수 있습니다. 이러한 상황에서는 세션이 종료되지 않도록 하는 것이 바람직할 수 있으며 사용자에게 세션 종료 여부를 결정할 수 있는 옵션을 허용하는 것이 더 바람직할 수 있습니다.

이벤트를 처리하여 세션이 종료되는 시기를 감지할 SessionEnding 수 있습니다. 애플리케이션 세션을 종료 하지 못하도록 해야 하는 경우는 SessionEndingCancelEventArgs 이벤트 처리기에 전달 된 인수를 제공 합니다 Cancel 로 설정 하는 true (기본값은 false).

가 처리되지 않거나 취소 Shutdown 되지 않고 처리되는 경우 SessionEnding 가 호출되고 Exit 이벤트가 발생합니다.

세션이 종료 되는 이유에 대 한 자세한 정보를 얻으려면 애플리케이션을 검사할 수 ReasonSessionEnding, 중 하나인 합니다 ReasonSessionEnding 값 (ReasonSessionEnding.LogoffReasonSessionEnding.Shutdown).

SessionEnding 콘솔 애플리케이션에서 발생 하지 않습니다.

SessionEnding 는 개체를 만드는 스레드에서만 발생합니다 Application .

SessionEnding XAML 브라우저 애플리케이션 (Xbap) 발생 하지 않습니다.

적용 대상

추가 정보