Home > DeveloperSection > Articles > Creating Worker Role in Windows Azure Application

Creating Worker Role in Windows Azure Application


Cloud Computing Cloud Computing 
Ratings:
7 Comment(s)
 5513  View(s)
Rate this:

Creating Worker Role in Windows Azure Application

Windows Azure has a project type i.e. worker role. Worker role applications are background processing application like windows process which runs on the background.

In this article I am going to explain how to create worker role project and the various fundamental methods which are executed in worker role projects.

Follow the steps given below to create or add Worker role in windows azure:

·         Open Microsoft Visual Studio 2010 as an administrator.

·         To create a new project FileNewProject.

·         Select Cloud template from the Installed Templates.

·         Select Windows Azure Project and enter the name of the project as WorkRoleExample.

·         Click OK to proceed.

Creating Worker Role in Windows Azure Application

·         To add a worker role to the solution, choose Worker Role and then choose the right arrow. The roles are displayed in the Windows Azure solution pane of the dialog box.

·         Click OK to add.

Creating Worker Role in Windows Azure Application

 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 initialized to value 5. This value is initialized in the 'OnStart' method. 'OnStart' method is executed the first time when your worker role is executed. 

public class WorkerRole : RoleEntryPoint

    {

        int intLoop = 0;

 

        public override bool OnStart()

        {

            // Set the maximum number of concurrent connections

            ServicePointManager.DefaultConnectionLimit = 12;

            intLoop = 5;

            bool result = true;

            while (result)

            {

                Thread.Sleep(1000);

                Trace.WriteLine("This is loop number " + intLoop, "Information");

                intLoop--;

                if (intLoop == 0)

                    result = false;

            }

 

            return base.OnStart();

        }

    }

 

After modifying the code in WorkerRole class, press F5 in order to debug your application. While debugging an application open Output window (Ctrl + W + O). The output should something like below:

Creating Worker Role in Windows Azure Application

To check the running instance, open the shortcut menu for the Windows Azure icon in the notification area and then choose Show Compute Emulator UI.

The Windows Azure Compute Emulator is displayed.

Creating Worker Role in Windows Azure Application

Here you can also check the output as output indicated with the white line in the above figure.

After reading this article you can easily create and use worker role in a windows azure application. I think this will help a lot.


How to create WorkerRole in windows azure?

By anil babu on   4 years ago
How to create WCFWorkerRole in windows azure and also perform All DML operations in database?
And also How to consume this service ASP.net webpages And perform all DML operations?
plz help me

What is OnStart metod()

By anil babu on   4 years ago
What is OnStart metod() ?
Can you explain that one?

OnStart metod()

By Rohit Kesharwani on   4 years ago
Hi,

'OnStart' method is executed the first time when your worker role is executed. It means it invoked only once when your worker role is started or executed.


How to create WCFWorkerRole in windows azure and also perform All DML operations in database?

By anil babu on   4 years ago
Thank you so much,
How to create WCFWorkerRole in windows azure and also perform All DML operations in database?
And also How to consume this service ASP.net webpages And perform all DML operations?




How to create WCFWorkerRole in windows azure and also perform All DML operations in database?

By Rohit Kesharwani on   4 years ago

Thank you

By anil babu on   4 years ago
Thats ok,
my question is I am develop only wcf service using WorkerRole ?
How to start?

In normal .net WCF service library,WCF service Application Templates is their in Cloud Template Worker role How can i Start?

I am new This Azure......... 


Don't want to miss updates? Please click the below button!

Follow MindStick