---
title: "Creating Worker Role in Windows Azure Application"  
description: "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"  
author: "Chris Anderson"  
published: 2012-01-23  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/861/creating-worker-role-in-windows-azure-application  
category: "cloud computing"  
tags: ["cloud computing"]  
reading_time: 2 minutes  

---

# 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 **File** – **New** – **Project**.

· 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](https://www.mindstick.com/mindstickarticle/2e519900-f53e-4a02-ac64-2aa0f412a6e1/images/58f99bc5-c1b0-4d1a-bd05-a8003d00d360.png)

· 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](https://www.mindstick.com/mindstickarticle/2e519900-f53e-4a02-ac64-2aa0f412a6e1/images/cacbf39c-072f-4220-bc22-2d008129621a.png)

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](https://www.mindstick.com/mindstickarticle/2e519900-f53e-4a02-ac64-2aa0f412a6e1/images/2099fabc-8cf5-49ea-87b1-533ef745e62c.png)

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](https://www.mindstick.com/mindstickarticle/2e519900-f53e-4a02-ac64-2aa0f412a6e1/images/a00d74c8-dc6b-4fda-aa02-a76cac26719d.png)

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.

---

Original Source: https://www.mindstick.com/articles/861/creating-worker-role-in-windows-azure-application

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
