Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8443631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:11:26+00:00 2026-06-10T09:11:26+00:00

I am adding a simple worker process to an underutilized Azure web role. I

  • 0

I am adding a simple worker process to an underutilized Azure web role. I have this web role running on 2 instances for reliability/uptime. This worker process was to be set to sleep for around 5 min before performing an action and then sleeping again. By adding this worker process to the web role it will be running on multiple instances and they will both try to perform the same action at the same time. Normally this problem is overcome by using a queue but I don’t need anything nearly that elaborate. I just something to keep the 2 instances from being completely syncronized.

The idea I had was to change the thread.sleep from a hard coded wait time to a random wait time as follows:

    Public Overrides Sub Run()

    Trace.WriteLine("Worker Role entry point called.", "Information")

    While (True)
        Dim r As New Random
        Dim wait As Integer = r.Next(60000, 600000)
        Dim Minutes As Decimal = wait / 60000
        Thread.Sleep(wait)
        Trace.WriteLine(String.Format("Worker Role - Triggered on {0:f}.  Waited {1:N2} Minutes.", Now(), Minutes), "Information")
    End While

    End Sub

Output from Instance 0:
Information: Worker Role entry point called.
Information: Worker Role – Triggered on Monday, August 27, 2012 9:37 AM. Waited 7.71 Minutes.
Information: Worker Role – Triggered on Monday, August 27, 2012 9:41 AM. Waited 4.25 Minutes.
Information: Worker Role – Triggered on Monday, August 27, 2012 9:49 AM. Waited 7.87 Minutes.
Information: Worker Role – Triggered on Monday, August 27, 2012 9:53 AM. Waited 4.77 Minutes.
Information: Worker Role – Triggered on Monday, August 27, 2012 10:03 AM. Waited 9.91 Minutes.

Output from Instance 1:
Information: Worker Role entry point called.
Information: Worker Role – Triggered on Monday, August 27, 2012 9:38 AM. Waited 9.47 Minutes.
Information: Worker Role – Triggered on Monday, August 27, 2012 9:44 AM. Waited 6.15 Minutes.
Information: Worker Role – Triggered on Monday, August 27, 2012 9:48 AM. Waited 3.41 Minutes.
Information: Worker Role – Triggered on Monday, August 27, 2012 9:49 AM. Waited 1.63 Minutes.
Information: Worker Role – Triggered on Monday, August 27, 2012 9:58 AM. Waited 8.26 Minutes.
Information: Worker Role – Triggered on Monday, August 27, 2012 10:01 AM. Waited 3.14 Minutes.

Does this plan have flaws that I’m not seeing? Thanks for your input!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:11:28+00:00Added an answer on June 10, 2026 at 9:11 am

    Well, to answer your titular question, this does nothing to guarantee both of them from doing something at the same time. But it would certainly make that less likely.

    That said, using an actual concurrency control mechanism doesn’t have to be “elaborate.” From http://blog.smarx.com/posts/simple-scheduling-in-windows-azure:

    AutoRenewLease.DoEvery(blob, TimeSpan.FromMinutes(5), () => {
        Trace.WriteLine("Doing stuff at {0:R}", DateTimeOffset.UtcNow);
    });
    

    Why not just do that? It’s available as a NuGet package, and it shortens your code. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form for generating reports that I am adding a jqueryUI
I have a simple JavaScript game that sends a score to PHP by adding
I have implemented a simple linux shell in c. Now, I am adding some
I have a simple module for adding the current user to a newly created
I have never worked with web services and rails, and obviously this is something
Context: I'm working on master adding a simple feature. After a few minutes I
Adding strings localization files in iPhone bundle is very simple and perfectly fine but
I'm looking for a simple way of adding a refresh mechanism to my UIWebView.
As a simple example, I'm adding 5 items to a new RabbitMQ(v 2.6.1) queue:
Simply put, I'm getting this error in the Product Admin of Magento after adding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.