Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

SessionChangeDescription Struct

Definition

Namespace:
System.ServiceProcess
Assembly:
System.ServiceProcess.ServiceController.dll
Assembly:
System.ServiceProcess.dll
Package:
System.ServiceProcess.ServiceController v11.0.0-preview.5.26302.115
Source:
SessionChangeDescription.cs
Source:
SessionChangeDescription.cs
Source:
SessionChangeDescription.cs
Source:
SessionChangeDescription.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Identifies the reason for a Terminal Services session change.

public value class SessionChangeDescription : IEquatable<System::ServiceProcess::SessionChangeDescription>
public value class SessionChangeDescription
public readonly struct SessionChangeDescription : IEquatable<System.ServiceProcess.SessionChangeDescription>
public struct SessionChangeDescription
public readonly struct SessionChangeDescription
type SessionChangeDescription = struct
Public Structure SessionChangeDescription
Implements IEquatable(Of SessionChangeDescription)
Public Structure SessionChangeDescription
Inheritance
SessionChangeDescription
Implements

Examples

The following code example shows the use of the SessionChangeDescription class in 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.

 // 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

Properties

Name Description
Reason

Gets the reason for the session change.

SessionId

Gets the session ID for the associated session.

Methods

Name Description
Equals(Object)

Determines whether the specified object is equal to the current session change description.

Equals(SessionChangeDescription)

Determines whether the specified session change description is equal to the current session change description.

GetHashCode()

Gets a hash code for the current session change description.

Operators

Name Description
Equality(SessionChangeDescription, SessionChangeDescription)

Returns a value indicating whether two SessionChangeDescription structures are equal.

Inequality(SessionChangeDescription, SessionChangeDescription)

Returns a value indicating whether two SessionChangeDescription structures are not equal.

Applies to


Feedback

Was this page helpful?