Understanding and implementing timers
The HotelGrain
class that we have created in the book so far has been getting messages from external clients for welcome greetings or check-in as shown in the following diagram. Ultimately, all the HotelGrain
classes have responded to an outside request.
But what if the grain needs to do some internal processing on a periodic basis. Timers provided by Orleans help in scheduling and creating periodic grain behavior without spanning multiple instances of the grain. Timers are asynchronous, single-threaded, and re-entrant so that a function can fire while the grain is awaiting. A grain can register multiple timers and can also cancel them when it is done with them. Timers are valid for the duration of the grain's activation, so they continue to fire until the grain is deactivated.
Grain.RegisterTimer
shown here is the method to register...