.NET Tutorials, Forums, Interview Questions And Answers
HomeTutorialArticlesForumInterview QuestionCode SnippetsTechnology NewsFun Zone Poll Certification Search
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Home >> Articles >> Azure >> Post New Resource Bookmark and Share

 Subscribe to Articles

Simple 6 steps to run your first Azure Worker Role Program

Posted By :Shivprasad koirala      Posted Date :04/01/2010   Points :25   Category: Azure    URL: http://www.questpond.com

Simple 6 steps to run your first Azure Worker Role Program. 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.
    


Simple 6 steps to run your first Azure Worker Role Program

 

Introduction

Step 1:- Ensure you have things at place

Step 2:- What will we do?

Step 3:- Select the worker role template

Step 4:- Import namespaces

Step 5:- Create class and override run and on start method


Step 6:- Run the project and watch the Azure console


 

Introduction


In our previous article http://www.dotnetspark.com/kb/702-windows-azure-faq-part-1.aspx .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 back ground processing application like windows process which runs on the back ground. 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 Azure Faq Part 1 :- Video1 Azure Faq Part 2 :- Video2.


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

In case you are a complete fresher to Azure, please ensure you have all the pre-requisite at place. You can read the below article to get the basic prerequisite http://www.dotnetspark.com/kb/1358-simple-5-steps-to-run-your-first-azure-program.aspx .
 

Step 2:- What will we do?
 

Worker roles are nothing but back ground process which runs on windows azure platform. We will create a simple background process which will run for 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 method
 

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 initialized to value 5. This is value is initialized 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 method. 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

Featured Articles


Best Practices No 5: - Detecting .NET application memory leaks
Memory leaks in .NET application have always being programmer's nightmare. Memory leaks are biggest problems when it comes to production servers. Productions servers normally need to run with least down time. Memory leaks grow slowly and after sometime they bring down the server by consuming huge chunks of memory. Maximum time people reboot the system, make it work temporarily and send a sorry note to the customer for the downtime. ... Read More
.NET Best Practice No: 1:- Detecting High Memory consuming functions in .NET code
One of the important factors for performance degradation in .NET code is memory consumption. Many developers just concentrate on execution time to determine performance bottle necks in a .NET application. Only measuring execution time does not clearly give idea of where the performance issue resides. Ok, said and done one of the biggest task is to understand which function, assembly or class has consumed how much memory. In this tutorial we will see how we can find which functions consume how much memory. This article discusses the best practices involved using CLR profiler for studying memory allocation.... Read More
How to improve your LINQ query performance by 5 X times ?
LINQ has been criticized by many early adopters for its performance issues. Well if you are just going to drag and drop using DBML code generator I am sure you will land up in to mess. Try doing this make a simple LINQ to SQL project using DBML and see your SQL profiler, I am sure you will never like to touch DBML code generator again. ... Read More
Responses
No response found. Be the first to respond this post
Post Comment
You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend