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

Tagged as

Six simple steps to run your first Azure Worker Role program

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

Contents

Introduction

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 two Azure basic videos which explain what Azure is all about:

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

History

  • 4 January, 2010: Initial post.

License

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

Share

About the Author

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

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


Comments and Discussions

 
QuestionHow to create WorkerRole in windows azure? PinmemberMember 917112827-Aug-12 1:46 
QuestionHelp Worker Role Pinmemberfdevia1-Aug-12 14:39 
GeneralMy vote of 5 PinmemberSandeep Ramani9-Sep-11 3:45 
GeneralMy vote of 5 PinmemberMD. SHAHDAT HOSAIN13-Jul-10 23:55 

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

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

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