SessionChangeDescription SessionChangeDescription SessionChangeDescription SessionChangeDescription Struct

定義

識別終端機服務工作階段變更的原因。Identifies the reason for a Terminal Services session change.

public value class SessionChangeDescription
public struct SessionChangeDescription
type SessionChangeDescription = struct
Public Structure SessionChangeDescription
繼承
SessionChangeDescriptionSessionChangeDescriptionSessionChangeDescriptionSessionChangeDescription

範例

下列程式碼範例示範如何在衍生自SessionChangeDescription ServiceBase的類別中, 于OnSessionChange方法的執行中使用類別。The following code example shows the use of the SessionChangeDescription class in an implementation of the OnSessionChange method in a class derived from ServiceBase. 這個程式碼範例是針對ServiceBase類別提供之較大範例的一部分。This code example is part of a larger example provided for the ServiceBase class.

        // Handle a session change notice
        protected override void OnSessionChange(SessionChangeDescription changeDescription)
        {
#if LOGEVENTS
            EventLog.WriteEntry("SimpleService.OnSessionChange", DateTime.Now.ToLongTimeString() +
                " - Session change notice received: " +
                changeDescription.Reason.ToString() + "  Session ID: " +
                changeDescription.SessionId.ToString());
#endif

            switch (changeDescription.Reason)
            {
                case SessionChangeReason.SessionLogon:
                    userCount += 1;
#if LOGEVENTS
                    EventLog.WriteEntry("SimpleService.OnSessionChange",
                        DateTime.Now.ToLongTimeString() +
                        " SessionLogon, total users: " +
                        userCount.ToString());
#endif
                    break;
                case SessionChangeReason.SessionLogoff:

                    userCount -= 1;
#if LOGEVENTS
                    EventLog.WriteEntry("SimpleService.OnSessionChange",
                        DateTime.Now.ToLongTimeString() +
                        " SessionLogoff, total users: " +
                        userCount.ToString());
#endif
                    break;
                case SessionChangeReason.RemoteConnect:
                    userCount += 1;
#if LOGEVENTS
                    EventLog.WriteEntry("SimpleService.OnSessionChange",
                        DateTime.Now.ToLongTimeString() +
                        " RemoteConnect, total users: " +
                        userCount.ToString());
#endif
                    break;
                case SessionChangeReason.RemoteDisconnect:
                    userCount -= 1;
#if LOGEVENTS
                    EventLog.WriteEntry("SimpleService.OnSessionChange",
                        DateTime.Now.ToLongTimeString() +
                        " RemoteDisconnect, total users: " +
                        userCount.ToString());
#endif
                    break;
                case SessionChangeReason.SessionLock:
#if LOGEVENTS
                    EventLog.WriteEntry("SimpleService.OnSessionChange",
                        DateTime.Now.ToLongTimeString() +
                        " SessionLock");
#endif
                    break;
                case SessionChangeReason.SessionUnlock:
#if LOGEVENTS
                    EventLog.WriteEntry("SimpleService.OnSessionChange",
                        DateTime.Now.ToLongTimeString() +
                        " SessionUnlock");
#endif
                    break;
                default:
                    break;
            }
        }
    ' Handle a session change notice
    Protected Overrides Sub OnSessionChange(ByVal changeDescription As SessionChangeDescription)
#If LOGEVENTS Then
        System.Diagnostics.EventLog.WriteEntry("SimpleService.OnSessionChange", DateTime.Now.ToLongTimeString() + " - Session change notice received: " + changeDescription.Reason.ToString() + "  Session ID: " + changeDescription.SessionId.ToString())
#End If

        Select Case changeDescription.Reason
            Case SessionChangeReason.SessionLogon
                userCount += 1
#If LOGEVENTS Then
                System.Diagnostics.EventLog.WriteEntry("SimpleService.OnSessionChange", DateTime.Now.ToLongTimeString() + " SessionLogon, total users: " + userCount.ToString())
#End If
            Case SessionChangeReason.SessionLogoff

                userCount -= 1
#If LOGEVENTS Then
                System.Diagnostics.EventLog.WriteEntry("SimpleService.OnSessionChange", DateTime.Now.ToLongTimeString() + " SessionLogoff, total users: " + userCount.ToString())
#End If
            Case SessionChangeReason.RemoteConnect
                userCount += 1
#If LOGEVENTS Then
                System.Diagnostics.EventLog.WriteEntry("SimpleService.OnSessionChange", DateTime.Now.ToLongTimeString() + " RemoteConnect, total users: " + userCount.ToString())
#End If
            Case SessionChangeReason.RemoteDisconnect
                userCount -= 1
#If LOGEVENTS Then
                System.Diagnostics.EventLog.WriteEntry("SimpleService.OnSessionChange", DateTime.Now.ToLongTimeString() + " RemoteDisconnect, total users: " + userCount.ToString())
#End If
            Case SessionChangeReason.SessionLock
#If LOGEVENTS Then
                System.Diagnostics.EventLog.WriteEntry("SimpleService.OnSessionChange", DateTime.Now.ToLongTimeString() + " SessionLock")
#End If
            Case SessionChangeReason.SessionUnlock
#If LOGEVENTS Then
                System.Diagnostics.EventLog.WriteEntry("SimpleService.OnSessionChange", DateTime.Now.ToLongTimeString() + " SessionUnlock")
#End If
            Case Else
        End Select

    End Sub

屬性

Reason Reason Reason Reason

取得工作階段變更的原因。Gets the reason for the session change.

SessionId SessionId SessionId SessionId

取得相關聯工作階段的工作階段識別碼。Gets the session ID for the associated session.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的工作階段變更描述。Determines whether the specified object is equal to the current session change description.

Equals(SessionChangeDescription) Equals(SessionChangeDescription) Equals(SessionChangeDescription) Equals(SessionChangeDescription)

判斷指定的工作階段變更描述是否等於目前的工作階段變更描述。Determines whether the specified session change description is equal to the current session change description.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

取得目前工作階段變更描述的雜湊碼。Gets a hash code for the current session change description.

運算子

Equality(SessionChangeDescription, SessionChangeDescription) Equality(SessionChangeDescription, SessionChangeDescription) Equality(SessionChangeDescription, SessionChangeDescription) Equality(SessionChangeDescription, SessionChangeDescription)

傳回值,指出兩個 SessionChangeDescription 結構是否相等。Returns a value indicating whether two SessionChangeDescription structures are equal.

Inequality(SessionChangeDescription, SessionChangeDescription) Inequality(SessionChangeDescription, SessionChangeDescription) Inequality(SessionChangeDescription, SessionChangeDescription) Inequality(SessionChangeDescription, SessionChangeDescription)

傳回值,指出兩個 SessionChangeDescription 結構是否不相等。Returns a value indicating whether two SessionChangeDescription structures are not equal.

適用於