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 8136233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:41:53+00:00 2026-06-06T10:41:53+00:00

I have an Azure worker role whose job is to periodically run some code

  • 0

I have an Azure worker role whose job is to periodically run some code against a SQL Azure database. Here’s my current code:

const int oneHour = 216000000; // milliseconds

while (true)
{
    var numConversions = SaveSeedsToSQL.ConvertRemainingPotentialQueryURLsToSeeds();
    SaveLogEntryToSQL.Save(new LogEntry { Count = numConversions });
    Thread.Sleep(oneHour);
}

Is Thread.Sleep(216000000) the best way of programming such regular but infrequent events or is there some kind of wake-up-and-run-again mechanism for Azure worker roles that I should be utilizing?

  • 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-06T10:41:55+00:00Added an answer on June 6, 2026 at 10:41 am

    This code works of course, but there are some problems:

    1. You can fail somewhere and this schedule gets all thrown off. That
      is important if you must actually do it at a specific time.
    2. There is no concurrency control here. If you want something only done once,
      you need a mechanism such that a single instance will perform the
      work and the other instances won’t.

    There are a few solutions to this problem:

    • Run the Windows Scheduler on the role (built in). That solves problem 1, but not 2.
    • Run Quartz.NET and schedule things. That solves #1 and depending on how you do it, also #2.
    • Use future scheduled queue messages in either Service Bus or Windows Azure queues. That solves both.

    The first two options work with caveats, so I think the last option deserves more attention. You can simply create a message(s) that your role(s) will understand and post it to the queue. Once the time comes, it becomes visible and your normally polling roles will see it and can work on it. The benefit here is that it is both time accurate as well as a single instance operates on it since it is a queue message. When completed with the work, you can have the instance schedule the next one and post it to the queue. We use this technique all the time. You only have to be careful that if for some reason your role fails before scheduling the next one, the whole system kinda fails. You should have some sanity checks and safeguards there.

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

Sidebar

Related Questions

I, Here is my situation. I have a worker role in my Azure who
I have a service hosted in a Worker Role in Azure. Clients connect over
I have a class library shared between an Azure Worker Role and a ASP.NET
We have a requirement to read an excel sheet from the Azure worker role.
I have deployed a Worker Role to an Azure instance with remote access enabled.
I would like to run a WebSocket server off a worker role in Azure.
I have created a Azure Worker Role Project. Target machine of the project has
I have an azure app on the cloud with a sql azure database. I
I have .Net Worker role (Azure) and my application write to local log files
I have a Worker Role which isn´t working on Cloud environment. When I run

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.