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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:17:13+00:00 2026-06-15T09:17:13+00:00

Consider the following table in SQL Server: Tasks (Payload nvarchar, DateToExecute datetime, DateExecuted datetime

  • 0

Consider the following table in SQL Server: Tasks (Payload nvarchar, DateToExecute datetime, DateExecuted datetime null).

Now we have two worker processes (2 Azure worker role instances in our case). Both of them periodically try to get records where DateExecuted IS NULL AND DateToExecute <= GETDATE(). Then they process that record and set (SQL update) DateExecuted to current date.

The problem is that a single task should be processed only once by a single worker instance.

What’s the best way to provide synchronization or locking for implementing such scenario?

  • 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-15T09:17:14+00:00Added an answer on June 15, 2026 at 9:17 am

    The easiest way to do locking over multiple roles/instances in Windows Azure is by using blob leases. Steve Marx created a great class for this called AutoRenewLease (source, NuGet, blog post). If you already have a timer or while loop, you can write code like this:

    using (var arl = new AutoRenewLease(leaseBlob))
    {
        if (arl.HasLease)
        {
            // Query Tasks table and do work....
        }
        else 
        {
            // Other worker is busy....
        }
    }
    

    Or you could use the DoEvery method which allows you to schedule your code every X minutes:

    AutoRenewLease.DoEvery(leaseBlob, TimeSpan.FromMinutes(15), () => {
        // Query Tasks table and do work....
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following table in SQL Server 2008: LanguageCode varchar(10) Language nvarchar(50) LanguageCode participates
Please consider the following SQL Server table and stored procedure. create table customers(cusnum int,
Consider the following sql server query , DECLARE @Table TABLE( Wages FLOAT ) INSERT
Consider the following Transact sql. DECLARE @table TABLE(val VARCHAR(255) NULL) INSERT INTO @table (val)
Consider the following SQL Server table: ID | X | Y ------+-------+------- 1 |
Possible Duplicate: SQL Server dynamic PIVOT query? I have temporary table with following structure:
Consider the following table which has the fields - id (int) and date_created (datetime):
Consider the following SQL (SQL Server 2008) statement: WITH MyResult AS ( SELECT Name,
Consider the following tables; test SQL> desc test; Name Null? Type ----------------------------------------- -------- ----------------------------
I am using MSSQL 2005 Server and I have the following SQL query. IF

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.