When or what's the best use to override RunAsync method of Stateless service in Service Fabric

1.4k views Asked by At

I've been using stateless service programming model but I haven't really override the RunAsync method to run application logic. When would you normally override this method?

1

There are 1 answers

5
LoekD On

Services can have both autonomous behavior and interactive behavior.

You can use CreateServiceInstanceListeners to create a communication listener, which allows interaction with your service.

Your service might (also) need to perform background tasks (not triggered by external callers). For example, it could be monitoring a Queue. You can use RunAsync for that, in there you'd start an endless loop. In the loop you would check the CancellationToken and then check the Queue for items and process them.

Other examples (without loops) are:

  • service initialization
  • pre-fetching data

An example is here.