Worker role internals
Building worker roles is fairly simple they are just class libraries that inherit from the Microsoft.ServiceHosting.ServiceRuntime.RoleEntryPoint
class. Worker roles are automatically started when their host instance is started. During startup, code in the OnStart()
method is executed. The OnStart()
method returns a Boolean value. If OnStart()
returns true
, the role is started and the Run()
method is called, whereas if OnStart()
returns false
, the role is stopped.
Our worker tasks should be coded in the Run()
method, and we should not return from the Run()
method. If we do, Azure will restart the worker role. Instead, and despite our best instincts, the code in the Run()
method should be enclosed inside an infinite loop. The way to stop a worker role is to stop the host instance. For this reason, worker roles that need to function independently should all be separated into individual instances.
When our worker role instance is being shut down by Azure, the OnStop...