Reading through various documentation and blogs, it sounds like OnStart is the place to initialize your objects and things you need before your role starts receiving traffic. It's not clear to me however if there is a case where OnStart can be called more than once using the same instance of the worker role class?
For instance I have an injection container and a database connection that should be created only once. I need to ensure that the role can't be stopped and started again leaving all the current objects in memory. In that case, it would seem better to use the worker role constructor to initialize the objects.
OnStart()
(a member of the RoleEntryPoint
class, and a method you need to override) is only called once in the role instance lifecycle. Return true
and then Run()
is called. Return false
and the role instance is recycled (restarted).
Remember that OnStart()
is called before the role instance is added to the load balancer. This gives you the opportunity to initialize things before traffic starts going to it.
FYI Here's more info about role lifecycle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With