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

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

ServiceBase.OnCustomCommand メソッド

派生クラス実装されると、OnCustomCommand は、サービス コントロール マネージャ (SCM) でカスタム コマンドサービス渡されるときに、実行されます。パラメータ値が設定されているコマンド発生時に実行されるアクション指定します

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

解説解説
使用例使用例

ServiceBase から派生したサービス クラスに対して OnCustomCommand メソッド実装する例を次に示します。このコード例は、ServiceBase クラストピック取り上げているコード例一部分です。

    ' Handle a custom command.
    Protected Overrides Sub
 OnCustomCommand(ByVal command As Integer)
#If LOGEVENTS Then
        System.Diagnostics.EventLog.WriteEntry("SimpleService.OnCustomCommand",
 DateTime.Now.ToLongTimeString() + _
            " - Custom command received: " + command.ToString())
#End If

        ' If the custom command is recognized,
        ' signal the worker thread appropriately.
        Select Case command
            Case Fix(SimpleServiceCustomCommands.StopWorker)
                ' Signal the worker thread to terminate.
                ' For this custom command, the main service
                ' continues to run without a worker thread.
                OnStop()

            Case Fix(SimpleServiceCustomCommands.RestartWorker)

                ' Restart the worker thread if necessary.
                OnStart(Nothing)

            Case Fix(SimpleServiceCustomCommands.CheckWorker)
#If LOGEVENTS Then
                ' Log the current worker thread state.
                System.Diagnostics.EventLog.WriteEntry("SimpleService.OnCustomCommand",
 _
                    DateTime.Now.ToLongTimeString() + _
                    " OnCustomCommand - Worker thread state =
 " + _
                    workerThread.ThreadState.ToString())
#End If


            Case Else
#If LOGEVENTS Then
                System.Diagnostics.EventLog.WriteEntry("SimpleService.OnCustomCommand",
 _
                DateTime.Now.ToLongTimeString())
#End If
        End Select

    End Sub 'OnCustomCommand
        // Handle a custom command.
        protected override void OnCustomCommand(int
 command)
        {
#if LOGEVENTS
            EventLog.WriteEntry("SimpleService.OnCustomCommand", DateTime.Now.ToLongTimeString()
 +
                " - Custom command received: " +
                command.ToString());
#endif

            // If the custom command is recognized,
            // signal the worker thread appropriately.

            switch (command)
            {
                case (int)SimpleServiceCustomCommands.StopWorker:
                    // Signal the worker thread to terminate.
                    // For this custom command, the main service
                    // continues to run without a worker thread.
                    OnStop();
                    break;

                case (int)SimpleServiceCustomCommands.RestartWorker:

                    // Restart the worker thread if necessary.
                    OnStart(null);
                    break;

                case (int)SimpleServiceCustomCommands.CheckWorker:
#if LOGEVENTS
                    // Log the current worker thread state.
                    EventLog.WriteEntry("SimpleService.OnCustomCommand"
, DateTime.Now.ToLongTimeString()
 +
                        " OnCustomCommand - Worker thread state = " +
                        workerThread.ThreadState.ToString());
#endif

                    break;

                default:
#if LOGEVENTS
                    EventLog.WriteEntry("SimpleService.OnCustomCommand"
,
                        DateTime.Now.ToLongTimeString());
#endif
                    break;
            }
        }
    // Handle a custom command.
protected:
    virtual void OnCustomCommand( int command
 ) override
    {
        Trace::WriteLine( DateTime::Now.ToLongTimeString() + " - Custom command
 received: " + command, "OnCustomCommand" );

        // If the custom command is recognized,
        // signal the worker thread appropriately.
        switch ( command )
        {
        case (int)SimpleServiceCustomCommands::StopWorker:

            // Signal the worker thread to terminate.
            // For this custom command, the main service
            // continues to run without a worker thread.
            OnStop();
            break;

        case (int)SimpleServiceCustomCommands::RestartWorker:

            // Restart the worker thread if necessary.
            OnStart( nullptr );
            break;

        case (int)SimpleServiceCustomCommands::CheckWorker:

            // Log the current worker thread state.
            Trace::WriteLine( DateTime::Now.ToLongTimeString() + " - Worker
 thread state = " + workerThread->ThreadState.ToString(), "OnCustomCommand"
 );
            break;

        default:
            Trace::WriteLine( DateTime::Now.ToLongTimeString() + " - Unrecognized
 custom command ignored!", "OnCustomCommand" );
            break;
        }
    }
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ServiceBase クラス
ServiceBase メンバ
System.ServiceProcess 名前空間
OnContinue
OnPause
OnPowerEvent
OnShutdown
OnStart
OnStop


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

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2024 GRAS Group, Inc.RSS