Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

RoleEntryPoint.Run Method

Updated: December 6, 2013

Runs code that is intended to be run for the life of the role instance.

Namespace: Microsoft.WindowsAzure.ServiceRuntime
Assembly: Microsoft.WindowsAzure.ServiceRuntime (in Microsoft.WindowsAzure.ServiceRuntime.dll)

public virtual void Run ()

The Run is considered the Main method for your application. Overriding the Run method is not required; the default implementation never returns. If you do override the Run method, your code should block indefinitely. If the Run method returns, the role is automatically recycled by raising the Stopping event and calling the OnStop method so that your shutdown sequences may be executed before the role is taken offline.

Override the Run method to run code for the life of the role instance. The following code example shows how to override the Run method:

public override void Run()
      Trace.WriteLine("WorkerRole entrypoint called", "Information");
      while (true)
         Trace.WriteLine("Working", "Information");
      // Add code here that runs in the role instance
   catch (Exception e)
      Trace.WriteLine("Exception during Run: " + e.ToString());
      // Take other action as needed.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Development Platforms

Windows Vista, Windows 7, Windows Server 2008, Windows 8.1, Windows Server 2012 R2, Windows 8 and Windows Server 2012

Target Platforms

Community Additions

© 2015 Microsoft