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

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

ServiceBase.OnStop メソッド

派生クラス実装されると、Stop コマンドサービス コントロール マネージャ (SCM) によってサービス送信されるときに実行されます。サービス実行停止したときに実行されるアクション指定します

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

解説解説
使用例使用例

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

    ' Stop this service.
    Protected Overrides Sub
 OnStop()
        ' New in .NET Framework version 2.0.
        Me.RequestAdditionalTime(4000)
        ' Signal the worker thread to exit.
        If Not (workerThread Is
 Nothing) AndAlso workerThread.IsAlive Then
#If LOGEVENTS Then
            System.Diagnostics.EventLog.WriteEntry("SimpleService.OnStop",
 DateTime.Now.ToLongTimeString() + _
                " - Stopping the service worker thread.")
#End If
            pause.Reset()
            Thread.Sleep(5000)

            workerThread.Abort()
        End If
        If Not (workerThread Is
 Nothing) Then
#If LOGEVENTS Then
            System.Diagnostics.EventLog.WriteEntry("SimpleService.OnStop",
 DateTime.Now.ToLongTimeString() + _
                " - OnStop Worker thread state = "
 + workerThread.ThreadState.ToString())
#End If
        End If
        ' Indicate a successful exit.
        Me.ExitCode = 0

    End Sub 'OnStop

        // Stop this service.
        protected override void OnStop()
        {
            // New in .NET Framework version 2.0.
            this.RequestAdditionalTime(4000);
            // Signal the worker thread to exit.
            if ((workerThread != null) &&
 (workerThread.IsAlive))
            {
#if LOGEVENTS
                EventLog.WriteEntry("SimpleService.OnStop", DateTime.Now.ToLongTimeString()
 +
                    " - Stopping the service worker thread.");
#endif
                pause.Reset();
                Thread.Sleep(5000);
                workerThread.Abort();

            }
            if (workerThread != null)
            {
#if LOGEVENTS
                EventLog.WriteEntry("SimpleService.OnStop", DateTime.Now.ToLongTimeString()
 +
                    " - OnStop Worker thread state = " +
                    workerThread.ThreadState.ToString());
#endif
            }
            // Indicate a successful exit.
            this.ExitCode = 0;
        }
    // Stop this service.
protected:
    virtual void OnStop() override
    {
        // Signal the worker thread to exit.
        if ( (workerThread != nullptr) && (workerThread->IsAlive)
 )
        {
            Trace::WriteLine( DateTime::Now.ToLongTimeString() + " - Stopping
 the service worker thread.", "OnStop" );
            workerThread->Abort();

            // Wait up to 500 milliseconds for the thread to terminate.
            workerThread->Join( 500 );
        }

        if ( workerThread != nullptr )
        {
            Trace::WriteLine( DateTime::Now.ToLongTimeString() + " - Worker
 thread state = " + workerThread->ThreadState.ToString(), "OnStop"
 );
        }
    }
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ServiceBase クラス
ServiceBase メンバ
System.ServiceProcess 名前空間
CanStop
OnContinue
OnPowerEvent
OnPause
OnShutdown
OnStart
OnCustomCommand


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

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

辞書ショートカット

すべての辞書の索引

「ServiceBase.OnStop メソッド」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS