SessionChangeReason 枚举
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定终端服务会话更改通知的原因。
public enum class SessionChangeReason
C#
public enum SessionChangeReason
type SessionChangeReason =
Public Enum SessionChangeReason
- 继承
名称 | 值 | 说明 |
---|---|---|
ConsoleConnect | 1 | 控制台会话已连接。 |
ConsoleDisconnect | 2 | 控制台会话已断开连接。 |
RemoteConnect | 3 | 远程会话已连接。 |
RemoteDisconnect | 4 | 远程会话已断开连接。 |
SessionLock | 7 | 会话已被锁定。 |
SessionLogoff | 6 | 用户已从会话注销。 |
SessionLogon | 5 | 用户已登录到会话。 |
SessionRemoteControl | 9 | 会话的远程控制状态已更改。 |
SessionUnlock | 8 | 会话已被解除锁定。 |
下面的代码示例演示如何SessionChangeReason在 派生自 ServiceBase的类中 方法的OnSessionChange实现中使用 枚举。 此代码示例是为 ServiceBase 类提供的一个更大示例的一部分。
C#
// 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
产品 | 版本 |
---|---|
.NET | 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 |