SessionChangeDescription 構造体
アセンブリ: System.ServiceProcess (system.serviceprocess.dll 内)


ServiceBase から派生したクラスの OnSessionChange メソッドの実装で、SessionChangeDescription クラスを使用するコード例を次に示します。このコード例は、ServiceBase クラスのトピックで取り上げているコード例の一部分です。
' 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 recieved: " + _ 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 'OnSessionChange
// 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; } }
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; } }


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- SessionChangeDescription 構造体のページへのリンク