Click here to Skip to main content
13,863,026 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


40 bookmarked
Posted 4 Jan 2010
Licenced CPOL

Six simple steps to run your first Azure Worker Role program

, 26 Feb 2014
Rate this:
Please Sign up or sign in to vote.
Six simple steps to run your first Azure Worker Role program.



In our previous article, we have seen five simple steps to create a web role application. Web role projects in Azure are like web applications. Azure has one more type of project, Worker role. Worker role applications are background processing applications like Windows processes which run in the background. In this article, we will try to understand the six basic steps to create a worker role project and as we run through the article, we will try to understand the various fundamental methods which are executed in worker role projects.

If you are really lazy like me, you can download my learn Azure Step by Step video which explain thoroughly all about Azure in step by step manner:

  • Azure Step by Step Tutorial: Video 1

My Other Azure FAQ Articles

Please feel free to download my free 600+ questions and answers eBook which covers .NET, ASP.NET, SQL Server, WCF, WPF, WWF@

Step 1: Ensure You Have Things In Place

In case you are a complete fresher to Azure, please ensure you have all the pre-requisites in place. You can read the following article to get the basic prerequisites:

Step 2: What Will We Do?

Worker roles are nothing but background processes which run on the Windows Azure platform. We will create a simple background process which will run X number of times and every time it runs, it will wait for 10000 ms.

Step 3: Select the Worker Role Template

Create a new project using the Worker role template as shown below:

Step 4: Import Namespaces

We need to import two namespaces, Microsoft.WindowsAzure.Diagnostics and Microsoft.WindowsAzure.ServiceRuntime. Diagnostic will help us to display a message using trace on the Azure profiler while ServiceRuntime provides functions for Azure services.

Step 5: Create Class and Override Run and OnStart Methods

The next step is to add a class and override the OnStart and Run methods. In the below code snippet, we have created a simple WorkerRole class which inherits from RoleEntryPoint.

We have also defined a simple loop count variable called intLoops which is initialised to value 5. This value is initialised in the OnStart method. The OnStart method is executed the first time your worker role is executed.

Now override the Run method with a simple loop which decrements the loop count and has a thread which sleeps for 10000 ms as every loop is executed.

Step 6: Run the Project and Watch the Azure Console

Now run the worker role and see your Azure console. You should see that one worker role instance is running.

We have displayed trace information at various places in the start and run methods. You can see in the Azure prompt the number of loops executed in the Azure diagnostic.

Event=Information,Level=Info,ThreadId=4148,=This is loop number 5
Event=Information,Level=Info,ThreadId=4148,=This is loop number 4
Event=Information,Level=Info,ThreadId=4148,=This is loop number 3
Event=Information,Level=Info,ThreadId=4148,=This is loop number 2
Event=Information,Level=Info,ThreadId=4148,=This is loop number 1 


  • 4 January, 2010: Initial post.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...

Comments and Discussions

QuestionMy vote of 5 Pin
Assil25-Jun-18 16:34
professionalAssil25-Jun-18 16:34 
QuestionHow to create WorkerRole in windows azure? Pin
Member 917112827-Aug-12 1:46
memberMember 917112827-Aug-12 1:46 
QuestionHelp Worker Role Pin
fdevia1-Aug-12 14:39
memberfdevia1-Aug-12 14:39 
GeneralMy vote of 5 Pin
Sandeepkumar Ramani9-Sep-11 3:45
memberSandeepkumar Ramani9-Sep-11 3:45 
GeneralMy vote of 5 Pin
Shahdat Hosain13-Jul-10 23:55
memberShahdat Hosain13-Jul-10 23:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190214.1 | Last Updated 26 Feb 2014
Article Copyright 2010 by Shivprasad koirala
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid