Share via


WindowsServiceLifetime Class

Definition

Listens for shutdown signal and tracks the status of the Windows service.

public ref class WindowsServiceLifetime : System::ServiceProcess::ServiceBase, Microsoft::Extensions::Hosting::IHostLifetime
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public class WindowsServiceLifetime : System.ServiceProcess.ServiceBase, Microsoft.Extensions.Hosting.IHostLifetime
public class WindowsServiceLifetime : System.ServiceProcess.ServiceBase, Microsoft.Extensions.Hosting.IHostLifetime
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
type WindowsServiceLifetime = class
    inherit ServiceBase
    interface IHostLifetime
type WindowsServiceLifetime = class
    inherit ServiceBase
    interface IHostLifetime
Public Class WindowsServiceLifetime
Inherits ServiceBase
Implements IHostLifetime
Inheritance
Attributes
Implements

Constructors

WindowsServiceLifetime(IHostEnvironment, IHostApplicationLifetime, ILoggerFactory, IOptions<HostOptions>, IOptions<WindowsServiceLifetimeOptions>)

Initializes a new instance of the WindowsServiceLifetime class.

WindowsServiceLifetime(IHostEnvironment, IHostApplicationLifetime, ILoggerFactory, IOptions<HostOptions>)

Initializes a new WindowsServiceLifetime instance.

Fields

MaxNameLength

Indicates the maximum size for a service name.

(Inherited from ServiceBase)

Properties

AutoLog

Indicates whether to report Start, Stop, Pause, and Continue commands in the event log.

(Inherited from ServiceBase)
CanHandlePowerEvent

Gets or sets a value indicating whether the service can handle notifications of computer power status changes.

(Inherited from ServiceBase)
CanHandleSessionChangeEvent

Gets or sets a value that indicates whether the service can handle session change events received from a Terminal Server session.

(Inherited from ServiceBase)
CanPauseAndContinue

Gets or sets a value indicating whether the service can be paused and resumed.

(Inherited from ServiceBase)
CanRaiseEvents

Gets a value indicating whether the component can raise an event.

(Inherited from Component)
CanShutdown

Gets or sets a value indicating whether the service should be notified when the system is shutting down.

(Inherited from ServiceBase)
CanStop

Gets or sets a value indicating whether the service can be stopped once it has started.

(Inherited from ServiceBase)
Container

Gets the IContainer that contains the Component.

(Inherited from Component)
DesignMode

Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
EventLog

Gets an event log you can use to write notification of service command calls, such as Start and Stop, to the Application event log.

(Inherited from ServiceBase)
Events

Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
ExitCode

Gets or sets the exit code for the service.

(Inherited from ServiceBase)
ServiceHandle

Gets the service control handle for the service.

(Inherited from ServiceBase)
ServiceName

Gets or sets the short name used to identify the service to the system.

(Inherited from ServiceBase)
Site

Gets or sets the ISite of the Component.

(Inherited from Component)

Methods

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose()

Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean)

Releases the resources used by the WindowsServiceLifetime.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type)

Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnContinue()

When implemented in a derived class, OnContinue() runs when a Continue command is sent to the service by the Service Control Manager (SCM). Specifies actions to take when a service resumes normal functioning after being paused.

(Inherited from ServiceBase)
OnCustomCommand(Int32)

When implemented in a derived class, OnCustomCommand(Int32) executes when the Service Control Manager (SCM) passes a custom command to the service. Specifies actions to take when a command with the specified parameter value occurs.

(Inherited from ServiceBase)
OnPause()

When implemented in a derived class, executes when a Pause command is sent to the service by the Service Control Manager (SCM). Specifies actions to take when a service pauses.

(Inherited from ServiceBase)
OnPowerEvent(PowerBroadcastStatus)

When implemented in a derived class, executes when the computer's power status has changed. This applies to laptop computers when they go into suspended mode, which is not the same as a system shutdown.

(Inherited from ServiceBase)
OnSessionChange(SessionChangeDescription)

Executes when a change event is received from a Terminal Server session.

(Inherited from ServiceBase)
OnShutdown()

Executes when a Shutdown command is sent to the service by the Service Control Manager (SCM). Triggers ApplicationStopping and waits for ApplicationStopped. Shortly after this method returns, the Service will be marked as stopped in SCM and the process may exit at any point.

OnStart(String[])

When implemented in a derived class, executes when a Start command is sent to the service by the Service Control Manager (SCM) or when the operating system starts (for a service that starts automatically). Specifies actions to take when the service starts.

OnStop()

Executes when a Stop command is sent to the service by the Service Control Manager (SCM). Triggers ApplicationStopping and waits for ApplicationStopped. Shortly after this method returns, the Service will be marked as stopped in SCM and the process may exit at any point.

RequestAdditionalTime(Int32)

Requests additional time for a pending operation.

(Inherited from ServiceBase)
RequestAdditionalTime(TimeSpan)

When this method is called from OnStart, OnStop, OnPause or OnContinue, the specified wait hint is passed to the Service Control Manager to avoid having the service marked as not responding.

(Inherited from ServiceBase)
ServiceMainCallback(Int32, IntPtr)

Registers the command handler and starts the service.

(Inherited from ServiceBase)
Stop()

Stops the executing service.

(Inherited from ServiceBase)
StopAsync(CancellationToken)

Asynchronously stops and shuts down the host. This method is called from StopAsync(CancellationToken).

ToString()

Returns a String containing the name of the Component, if any. This method should not be overridden.

(Inherited from Component)
WaitForStartAsync(CancellationToken)

Asynchronously waits until start is complete before continuing. This method is called at the beginning of StartAsync(CancellationToken). This can be used to delay startup until signaled by an external event.

Events

Disposed

Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

Applies to