Application.SessionEnding 이벤트
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
사용자가 운영 체제를 로그오프하거나 종료하여 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).
처리되지 않거나 취소 SessionEnding 되지 않고 처리되는 경우 Shutdown 호출되고 Exit 이벤트가 발생합니다.
세션이 종료되는 이유에 대한 자세한 정보를 얻기 위해 애플리케이션은 값(ReasonSessionEnding및ReasonSessionEnding) 중 ReasonSessionEnding.Logoff 하나인 검사를 ReasonSessionEnding.Shutdown수행할 수 있습니다.
SessionEnding 는 콘솔 애플리케이션에서 발생하지 않습니다.
SessionEnding 는 개체를 만드는 스레드에서만 발생합니다 Application .
SessionEnding XBAP(XAML 브라우저 애플리케이션)에 대해 발생하지 않습니다.