Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Hosted-services / Azure

Azure Tutorial; Be in Cloud (Part 4) [Worker Role]

0.00/5 (No votes)
10 Jan 2011CPOL2 min read 12.1K  
Azure Tutorial; Be in Cloud (Part 4) [Worker Role]

Windows Azure - Compute (Worker Role)

Before we start of with the worker role, we might talk about few things over the course which we have already discussed on our previous part. If you haven't read the previous part and you aren't able to follow something, I would recommend reading the previous part.

As I already briefed in part 2, the worker role is basically a worker process which is normally configured to run on an infinite loop. We will create something similar to what we spoke about.

Create an Application

As we have already created a solution, we will make you use the same.

Now to add a project, in the solution explorer, right click on the "Roles" folder and click "Add -> New Worker Role Project". We will name it as "CloudTutorialWorker". Now as we already saw in the previous part, there will be another entry "CloudTutorialWorker" in the "Roles" folder which contain similar settings as in a web role.

We will not talk about the settings and other features about the project as we have already covered the same in the previous project.

Let's Discuss Code

Before we go ahead and run the application, we will have a look on what the code is and how does it work.

As in a normal worker or windows service, there are two methods auto populated; "Run" and "OnStart". You can also override "OnStop" event to do functionalities on stop of the process.

In our code, it is written to show a log info "Working" every 10 seconds. Similarly, we can write any process to run endlessly.

Let's go ahead and run the application. Press F5 and it will start the application as we saw in our previous part. So when you run the application, you will find the web page being shown. So how do we find the worker role running. Open the simulation environment and have a look at the "Development Fabric".

Now as in the picture, we have both and the "CloudTutorialWeb" and "CloudTutorialWorker" running and if you select the worker, we could see the information popping up for every 10 seconds as we have programmed.

Now you can apply your own logic and work on the same. We will discuss more on the application while we try writing samples which will make use of the entire Azure technology.

What's Next

Now we are done with the "Worker Role" and the "Compute" section of the Azure technology. Our agenda for the next part would be on the "Storage" and we will also discuss the various options it offers and will try to code on the same.

License

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