ServiceBase.RequestAdditionalTime メソッド
アセンブリ: System.ServiceProcess (system.serviceprocess.dll 内)
構文
Dim instance As ServiceBase Dim milliseconds As Integer instance.RequestAdditionalTime(milliseconds)
解説
RequestAdditionalTime メソッドはオーバーライドされた OnContinue、OnPause、OnStart、または OnStop メソッドから呼び出され、保留中の操作の延長時間を要求して、サービス コントロール マネージャ (SCM) がサービスに応答なしのマークを付けないようにします。保留中の操作が Continue、Pause、Start、または Stop のいずれでもない場合は、InvalidOperationException がスローされます。
ServiceBase から派生したクラスで RequestAdditionalTime メソッドを使用するコード例を次に示します。このコード例は、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" ); } }
プラットフォーム
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.RequestAdditionalTime メソッドのページへのリンク