Click or drag to resize

NeonServiceRunAsync Method

Starts the service if it's not already running. This will call OnRunAsync, which is your code that actually implements the service. Note that any service dependencies specified by Dependencies will be verified as ready before OnRunAsync will be called.

Namespace:  Neon.Service
Assembly:  Neon.Service (in Neon.Service.dll) Version: 2.14.0
public virtual Task<int> RunAsync(
	bool disableProcessExit = false


disableProcessExit (Optional)
Type: SystemBoolean
Optionally specifies that the hosting process should not be terminated when the service exists. This is typically used for testing or debugging. This defaults to false.

Return Value

Type: TaskInt32
The service exit code.
Note Note
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 by 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. You'll need to perform this check frequently so you may need to use timeouts to prevent blocking code from blocking for too long.

Note Note
It is not possible to restart a service after it's been stopped.
See Also