Click here to Skip to main content
Click here to Skip to main content

Simple 6 Steps to Run your First Azure Worker Role Program

By , 1 Mar 2010
 

Article Updated 1:- Simple 5 steps to run your first Azure program 2:- Simple 7 steps to run your first Azure Blob Program 3:- 7 simple steps to run your first Azure Queue program 4:- 9 simple steps to run your first Azure Table Program

Simple 6 Steps to Run your First Azure Worker Role Program

Introduction

In our previous article, we have seen 5 simple steps to create web role application. Web role projects in Azure are like web applications. Azure has one more type of project, i.e., worker role. Worker role applications are background processing applications like Windows process which runs in the background. In this article, we will try to understand 6 basic steps to create 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 two Azure basic videos which explain what Azure is all about:

 

My other Azure Faq Articles

 

Please feel free to download my free 500 question and answer eBook which covers .NET, ASP.NET, SQL Server, WCF, WPF, WWF@ http://www.questpond.com.

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 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

So create a new project using the worker role template as shown below:

Step 4: Import Namespaces

We need to import two namespaces, one is ‘Microsoft.WindowsAzure.Diagnostics’ and ‘Microsoft.WindowsAzure.ServiceRuntime’. Diagnostic will help us to display 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 method and Run method. In the below code snippet, we have created a simple WorkerRole class which inherits from RoleEntryPoint.

We have also defined as simple loop count variable called as intLoops which is initialised to value 5. This value is initialised in the OnStart method. 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 had displayed trace information at various places in start and run methods. You can see in the Azure prompt the number of loops executed in 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 

History

  • 4th January, 2010: Initial post

License

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

About the Author

Shivprasad koirala
Architect http://www.questpond.com
India India
Member

I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small
E-learning company in India. We are very much active in making training videos ,
writing books and corporate trainings. Do visit my site for 
.NET, C# , design pattern , WCF , Silverlight
, LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server  training 
and Interview questions and answers


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHow to create WorkerRole in windows azure?memberMember 917112827 Aug '12 - 0:46 
QuestionHelp Worker Rolememberfdevia1 Aug '12 - 13:39 
GeneralMy vote of 5memberSandeep Ramani9 Sep '11 - 2:45 
GeneralMy vote of 5memberMD. SHAHDAT HOSAIN13 Jul '10 - 22:55 

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130513.1 | Last Updated 2 Mar 2010
Article Copyright 2010 by Shivprasad koirala
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid