Search code examples
c#azureazure-worker-roles

How to check if Worker Role is running in Azure Emulator


I was wondering if there was a way to check if the worker role was running inside the emulator. I have 2 worker roles and one of them shouldn't run locally, but since they are both in the same Azure Cloud Project, they both run.

One way around it is to use #if !DEBUG and surround all the code inside the main loop, but it feels wrong.

Is there something like ASP.Net's Request.IsLocal?

Vote To Reopen: While I have no doubt that this question is a duplicate in the strictest sense of the meaning, the question linked from here uses only the old terminology and would never have been found by a person searching today for the Windows Azure terms and namings that are currently used by the SDK.


Solution

  • The easiest way is to check it via RoleEnvironment.IsEmulated. For more information have a look at this thread. According to the documentation it will return

    true, if the role instance is running in the compute emulator; otherwise, false.