ServiceBase.OnSessionChange メソッド
アセンブリ: System.ServiceProcess (system.serviceprocess.dll 内)
構文Dim changeDescription As SessionChangeDescription Me.OnSessionChange(changeDescription)
使用例ServiceBase から派生したクラスで OnSessionChange メソッドを実装するコード例を次に示します。このコード例は、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; } }
.NET Framework のセキュリティ
プラットフォーム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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照ServiceBase クラス
ServiceBase メンバ
System.ServiceProcess 名前空間
CanHandleSessionChangeEvent
SessionChangeDescription
Weblioに収録されているすべての辞書からServiceBase.OnSessionChange メソッドを検索する場合は、下記のリンクをクリックしてください。
全ての辞書からServiceBase.OnSessionChange メソッド
を検索
- ServiceBase.OnSessionChange メソッドのページへのリンク