Export (0) Print
Expand All

ServiceBase.OnSessionChange Method

Note: This method is new in the .NET Framework version 2.0.

Executes when a change event is received from a Terminal Server session.

Namespace: System.ServiceProcess
Assembly: System.ServiceProcess (in system.serviceprocess.dll)

protected:
virtual void OnSessionChange (
	SessionChangeDescription changeDescription
)
protected void OnSessionChange (
	SessionChangeDescription changeDescription
)
protected function OnSessionChange (
	changeDescription : SessionChangeDescription
)

Parameters

changeDescription

A SessionChangeDescription structure that identifies the change type.

The following code example shows an implementation of the OnSessionChange method in a class derived from ServiceBase. This code example is part of a larger example provided for the ServiceBase class.

protected:
    virtual void OnSessionChange(SessionChangeDescription changeDescription) override
    {
        Trace::WriteLine( DateTime::Now.ToLongTimeString() + " - Change description received: " 
            + changeDescription.ToString(), "OnSessionChange" );

        switch (changeDescription.Reason)
        {
        case SessionChangeReason::SessionLogon:
            userCount += 1;
            Trace::WriteLine( DateTime::Now.ToLongTimeString() + 
                " SessionLogon, total users: " + 
                userCount.ToString(), "OnSessionChange" );
            break;
        case SessionChangeReason::SessionLogoff:
            userCount -= 1;
            Trace::WriteLine( DateTime::Now.ToLongTimeString() + 
                " SessionLogoff, total users: " + 
                userCount.ToString(), "OnSessionChange" );
            break;
        case SessionChangeReason::RemoteConnect:
            userCount += 1;
            Trace::WriteLine( DateTime::Now.ToLongTimeString() + 
                " RemoteConnect, total users: " + 
                userCount.ToString(), "OnSessionChange" );
            break;
        case SessionChangeReason::RemoteDisconnect:
            userCount -= 1;
            Trace::WriteLine( DateTime::Now.ToLongTimeString() + 
                " RemoteDisconnect, total users: " + 
                userCount.ToString(), "OnSessionChange" );
            break;
        case SessionChangeReason::SessionLock:
            Trace::WriteLine( DateTime::Now.ToLongTimeString() + 
                " SessionLock", "OnSessionChange" );
            break;
        case SessionChangeReason::SessionUnlock:
			Trace::WriteLine( DateTime::Now.ToLongTimeString() + 
                " SessionUnlock", "OnSessionChange" );
            break;

        default:
            Trace::WriteLine( DateTime::Now.ToLongTimeString() + 
                " - Unhandled session change event.", "OnSessionChange" );
            break;
        }
    }

  • Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft