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?
Asked
Active
Viewed 1,467 times
1 Answers
6
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.

LoekD
- 11,402
- 17
- 27
-
The example is a stateful service but I am looking for stateless service. – alltej Jan 04 '17 at 12:39
-
The story is the same for both Stateless and Stateful services. – LoekD Jan 04 '17 at 12:42
-
It's the same but in Stateful services it has the StateManager to access the reliable dictionary or queue. So stateful services makes sense to run some process inside RunAsync method. But in stateless service (there are no queues/dictionary), I was just wondering when/what code do you want to put in there since in stateless service I will call the method I created directly. – alltej Jan 04 '17 at 13:11
-
You could be monitoring an external service, polling an api, for example. Or get reference data from another service/datastore to make the response time of interaction request faster. Or use it to monitor other services and send custom health reports. – LoekD Jan 04 '17 at 13:27
-
That's what I thought also. Thanks! – alltej Jan 04 '17 at 19:56