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

  • Home
  • SEARCH
  • 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 609685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:35:34+00:00 2026-05-13T17:35:34+00:00

I basically have an application that has, say 5 threads, which each read from

  • 0

I basically have an application that has, say 5 threads, which each read from a table. The query is a simple SELECT TOP 1 * from the table, but I want to enforce a lock so that the next thread will select the next record from the table and not the locked one. When the application has finished it’s task, it will update the locked record and release the lock and repeat the process again. Is this possible?

  • 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-05-13T17:35:35+00:00Added an answer on May 13, 2026 at 5:35 pm

    The kind of approach I’d recommend is to have a field in the record along the lines of that indicates whether the record is being processed or not. Then implement a “read next from the queue” sproc that does the following, to ensure no 2 processes pick up the same record:

    BEGIN TRANSACTION
    
    -- Find the next available record that's not already being processed.
    -- The combination of UPDLOCK and READPAST hints makes sure 2 processes don't 
    -- grab the same record, and that processes don't block each other.
    SELECT TOP 1 @ID = ID
    FROM YourTable WITH (UPDLOCK, READPAST)
    WHERE BeingProcessed = 0
    
    -- If we've found a record, set it's status to "being processed"
    IF (@ID IS NOT NULL)
        UPDATE YourTable SET BeingProcessed = 1 WHERE ID = @ID
    
    COMMIT TRANSACTION
    
    -- Finally return the record we've picked up
    IF (@ID IS NOT NULL)
        SELECT * FROM YourTable WHERE ID = @ID
    

    For more info on these table hints, see MSDN

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

Sidebar

Related Questions

I basically have a page which shows a processing screen which has been flushed
We have a set of applications that basically display a bunch of bitmaps and
I have basically two separate sites, a SharePoint collaboration site, and an ASP.Net application
I have an ASP.NET application. Basically the delivery process is this one : Nant
I have an .net C# console application (not a service). it basically connects to
I have an old PowerBuilder application that we are slowly phasing out. We are
Im writing a WPF application that has a zoom and pan ability, but what
I have a particular application that needs to calculate something very specific, and while
Say there is a div that has content and a youtube link. I want
This is a question that has been bothering me for sometime. My application uses

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.