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

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

ServiceBase.OnPause メソッド

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

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

解説解説

OnPause使用してサービスPause コマンド受け取ったときに発生する処理を指定します。CanPauseAndContinue プロパティtrue場合OnPauseオーバーライドされます

サービス アドイン使用して、またはプログラムによって、一時中断されたサービス継続する場合は、OnContinue 処理が実行されサービス再度アクティブなります

Pause コマンドは、アプリケーション特定のイベントに対して反応できるようにするだけです。OnPause は、実行するように定義していないサービスに対しては何も実行しません。

Pauseすべてのシステム リソース解放する必要がないため、Pause 要求サービス送信しても、システム リソース保持されます。たとえば、このプロセススレッド開かれた場合は、サービス停止するではなく一時中断すると、スレッド開いたままの状態に保つことができ、サービス継続するときに再割り当ての必要がなくなりますすべてのシステム リソース解放するように Pause定義すると、PauseStop コマンド同じよう動作します

CanPauseAndContinuetrue設定しOnPause および OnContinueオーバーライドして、SCMPause 要求または Continue 要求サービスに渡すときに発生する処理を指定しますOnPause の処理を元に戻すには、OnContinue実装する必要があります

CanPauseAndContinuefalse場合SCMPause 要求または Continue 要求サービス渡さないため、OnPause メソッドOnContinue メソッドは、実装されている場合でも呼び出されません。SCM では、CanPauseAndContinuefalse設定されていると、Pause コントロールContinue コントロール無効になります

使用例使用例

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

    ' Pause the service.
    Protected Overrides Sub
 OnPause()
        ' Pause the worker thread.
        If Not (workerThread Is
 Nothing) AndAlso workerThread.IsAlive AndAlso
 (workerThread.ThreadState And System.Threading.ThreadState.Suspended Or System.Threading.ThreadState.SuspendRequested) = 0 Then
#If LOGEVENTS Then
            System.Diagnostics.EventLog.WriteEntry("SimpleService.OnPause",
 DateTime.Now.ToLongTimeString() + _
                " - Pausing the service worker thread.")
#End If

            pause.Reset()
            Thread.Sleep(5000)
        End If

        If Not (workerThread Is
 Nothing) Then
#If LOGEVENTS Then
            System.Diagnostics.EventLog.WriteEntry("SimpleService.OnPause",
 DateTime.Now.ToLongTimeString() + _
                " OnPause - Worker thread state = "
 + workerThread.ThreadState.ToString())
#End If
        End If

    End Sub 'OnPause

        // Pause the service.
        protected override void OnPause()
        {
            // Pause the worker thread.
            if ((workerThread != null) &&
                (workerThread.IsAlive) &&
                ((workerThread.ThreadState &
                 (System.Threading.ThreadState.Suspended | System.Threading.ThreadState.SuspendRequested))
 == 0))
            {
#if LOGEVENTS
                EventLog.WriteEntry("SimpleService.OnPause", DateTime.Now.ToLongTimeString()
 +
                    " - Pausing the service worker thread.");
#endif

                pause.Reset();
                Thread.Sleep(5000);
            }

            if (workerThread != null)
            {
#if LOGEVENTS
                EventLog.WriteEntry("SimpleService.OnPause", DateTime.Now.ToLongTimeString()
 +
                    " OnPause - Worker thread state = " +
                    workerThread.ThreadState.ToString());
#endif
            }
        }
    // Pause the service.
protected:
    virtual void OnPause() override
    {
        // Pause the worker thread.
        if ( (workerThread != nullptr) && (workerThread->IsAlive)
 && ((workerThread->ThreadState & (System::Threading::ThreadState::Suspended
 | System::Threading::ThreadState::SuspendRequested)) == (System::Threading::ThreadState)0) )
        {
            Trace::WriteLine( DateTime::Now.ToLongTimeString() + " - Suspending
 the service worker thread.", "OnPause" );
            workerThread->Suspend();
        }

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



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2026 GRAS Group, Inc.RSS