StatefulServiceBase.RunAsync(CancellationToken) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
This method is implemented as a processing loop and will only be called when the replica is primary with write status. Override this method with the application logic.
For information about Reliable Services life cycle please see https://docs.microsoft.com/azure/service-fabric/service-fabric-reliable-services-lifecycle
protected virtual System.Threading.Tasks.Task RunAsync (System.Threading.CancellationToken cancellationToken);
abstract member RunAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task
override this.RunAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task
Protected Overridable Function RunAsync (cancellationToken As CancellationToken) As Task
Parameters
- cancellationToken
- CancellationToken
Cancellation token to monitor for cancellation requests.
Returns
A Task that represents outstanding operation.
Remarks
Please ensure you follow these guidelines when overriding RunAsync(CancellationToken):
- Make sure
cancellationToken
passed to RunAsync(CancellationToken) is honored and once it has been signaled, RunAsync(CancellationToken) exits gracefully as soon as possible. Please note that if RunAsync(CancellationToken) has finished its intended work, it does not need to wait forcancellationToken
to be signaled and can return gracefully. - Service Fabric runtime does not handle all exception(s) escaping from RunAsync(CancellationToken). If an unhandled exception escapes from RunAsync(CancellationToken), then Service Fabric runtime takes following action(s):
- If a FabricException (or one of its derived exception) escapes from RunAsync(CancellationToken), Service Fabric runtime will restart this service replica. A health warning will be appear in Service Fabric Explorer containing details about unhandled exception.
- If an OperationCanceledException escapes from RunAsync(CancellationToken) and Service Fabric runtime has requested cancellation by signaling
cancellationToken
passed to RunAsync(CancellationToken), Service Fabric runtime handles this exception and considers it as graceful completion of RunAsync(CancellationToken). - If an OperationCanceledException escapes from RunAsync(CancellationToken) and Service Fabric runtime has NOT requested cancellation by signaling
cancellationToken
passed to RunAsync(CancellationToken), the process that is hosting this service replica is brought down. This will impact all other service replicas that are hosted by the same process. The details about unhandled exceptions can be viewed in Windows Event Viewer. - If an exception of any other type escapes from RunAsync(CancellationToken) then the process that is hosting this service replica is brought down. This will impact all other service replicas that are hosted by the same process. The details about unhandled exceptions can be viewed in Windows Event Viewer.
Failing to conform to these guidelines can cause fail-over, reconfiguration or upgrade of your service to get stuck and can impact availability of your service.
Applies to
Azure SDK for .NET