Click or drag to resize

ProcessTerminator Class

Gracefully handles SIGTERM signals sent to a process to terminate itself.
Inheritance Hierarchy

Namespace:  Neon.Kube.Service
Assembly:  Neon.Kube.Service (in Neon.Kube.Service.dll) Version: 2.1.0
public sealed class ProcessTerminator

The ProcessTerminator type exposes the following members.

Public methodProcessTerminator
Public propertyCancellationToken
Returns the CancellationToken that will be cancelled when a termination signal is received or Exit(Int32) is called explicitly.
Public propertyCancellationTokenSource
Returns the CancellationTokenSource that can be used to cancel any outstanding operations before terminating a process.
Public propertyDisableProcessExit
Optionally indicates that the terminator should not actually terminate the hosting process. This is typically enabled for testing or debugging.
Public propertyStopEvent
Returns the AsyncManualResetEvent that will be raised when the service is being stopped.
Public propertyTerminateNow
Returns true when the application has been signalled to terminate.
Public propertyTimeout
Returns the termination timeout.
Public methodAddDisposable
Adds a IDisposable instance that will be disposed when the process is being terminated. This can be a handy way to hook AsyncPeriodicTask and other components into a ProcessTerminator.
Public methodAddHandler
Adds a termination handler.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodExit
Cleanly terminates the current process.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodReadyToExit
Indicates that the application has gracefully stopped and is ready to be terminated.
Public methodSignal
Emulates a signal instructing the service to close. This will typically be used for unit testing services.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)

This class listens for a termination signal and then gives the process some time to gracefully save state. The termination timeout defaults to 10 seconds but a custom value may be passed to the constructor.

Note Note
The parent process or operating system typically enforces its own maximum timeout, so your process may still be killed before your timeout is reached.

This class provides two ways for the application to reach to a termination signal. Programs using the async/await pattern can monitor the CancellationToken returned by the CancellationToken property.

Applications may also use AddHandler(Action) to add one more more methods that will be called when a termination signal is received. Each handler will be called in parallel on its own thread.

Finally, you map pass one or more IDisposable instances to AddDisposable(IDisposable). Dispose will be called for each of these in parallel on its own thread. This can be a handy way of hooking AsyncPeriodicTask instances and other structures into a ProcessTerminator.

Applications should call ReadyToExit when they have gracefully stopped any activities and saved state so that the process will be terminated immediately. Otherwise, the process will be terminated when the parent process' timeout is finally exceeded.

Applications can also call Exit(Int32) to proactively signal that the process should terminate gracefully.

See Also