This documentation is archived and is not being maintained.

ServiceBase.RequestAdditionalTime Method

Note: This method is new in the .NET Framework version 2.0.

Requests additional time for a pending operation.

Namespace: System.ServiceProcess
Assembly: System.ServiceProcess (in system.serviceprocess.dll)

'Declaration
<ComVisibleAttribute(False)> _
Public Sub RequestAdditionalTime ( _
	milliseconds As Integer _
)
'Usage
Dim instance As ServiceBase
Dim milliseconds As Integer

instance.RequestAdditionalTime(milliseconds)
/** @attribute ComVisibleAttribute(false) */ 
public void RequestAdditionalTime (
	int milliseconds
)
ComVisibleAttribute(false) 
public function RequestAdditionalTime (
	milliseconds : int
)

Parameters

milliseconds

The requested time in milliseconds.

Exception typeCondition

InvalidOperationException

The service is not in a pending state.

The RequestAdditionalTime method is intended to be called by the overridden OnContinue, OnPause, OnStart, or OnStop methods to request additional time for a pending operation, to prevent the Service Control Manager (SCM) from marking the service as not responding. If the pending operation is not a continue, pause, start, or stop, an InvalidOperationException is thrown.

The following code example shows the use of the RequestAdditionalTime method in a class derived from ServiceBase. This code example is part of a larger example provided for the ServiceBase class.

    ' 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


  • Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Show: