public virtual Task<int> RunAsync( bool disableProcessExit = false )
Public Overridable Function RunAsync ( Optional disableProcessExit As Boolean = false ) As Task(Of Integer)
public: virtual Task<int>^ RunAsync( bool disableProcessExit = false )
abstract RunAsync : ?disableProcessExit : bool (* Defaults: let _disableProcessExit = defaultArg disableProcessExit false *) -> Task<int> override RunAsync : ?disableProcessExit : bool (* Defaults: let _disableProcessExit = defaultArg disableProcessExit false *) -> Task<int>
|For production, this method will not return until the service is expicitly stopped via a call to Stop or the Terminator handles a stop signal. For test environments, this method will call OnRunAsync on a new thread and returns immediately while the service continues to run in parallel.|
Service implementations must honor Terminator termination signals exiting the OnRunAsync method reasonably quickly (within 30 seconds by default) when these occur. They can do this by passing CancellationToken for async calls and then catching the TaskCanceledException and returning from OnRunAsync.
Another technique for synchronous code is to explicitly check the CancellationToken token's IsCancellationRequested property and return from your OnRunAsync method when this is true. This You'll need to perform this check frequently so you may need to use timeouts to prevent blocking code from blocking for too long.
|It is not possible to restart a service after it's been stopped.|