ServiceBase.OnSessionChange メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ServiceBase.OnSessionChange メソッドの意味・解説 

ServiceBase.OnSessionChange メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

変更イベントターミナル サーバー セッションから受信され場合実行します

名前空間: System.ServiceProcess
アセンブリ: System.ServiceProcess (system.serviceprocess.dll 内)
構文構文

Protected Overridable Sub
 OnSessionChange ( _
    changeDescription As SessionChangeDescription _
)
Dim changeDescription As SessionChangeDescription

Me.OnSessionChange(changeDescription)
protected virtual void OnSessionChange (
    SessionChangeDescription changeDescription
)
protected:
virtual void OnSessionChange (
    SessionChangeDescription changeDescription
)
protected void OnSessionChange (
    SessionChangeDescription changeDescription
)
protected function OnSessionChange (
    changeDescription : SessionChangeDescription
)

パラメータ

changeDescription

変更種類識別する SessionChangeDescription 構造体

使用例使用例

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 のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ServiceBase クラス
ServiceBase メンバ
System.ServiceProcess 名前空間
CanHandleSessionChangeEvent
SessionChangeDescription


このページでは「.NET Framework クラス ライブラリ リファレンス」からServiceBase.OnSessionChange メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からServiceBase.OnSessionChange メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からServiceBase.OnSessionChange メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

ServiceBase.OnSessionChange メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ServiceBase.OnSessionChange メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS