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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:03:11+00:00 2026-05-18T01:03:11+00:00

I have Tasks table: Id (PK), TaskName, Status Status is one of: Queued ,

  • 0

I have Tasks table: Id (PK), TaskName, Status
Status is one of: Queued, Busy, Complete.
I want to use multiple threads to process the tasks, and for that I need to be able to do in one operation:

var task = db.Tasks.FirstOrDefault(t=>t.Status == (byte) TaskStatus.Queued);
task.Status = (byte) TaskStatus.Busy;
db.SubmitChanges();

Obviously if operation is not atomic I can get concurrency issues. What is (if one exists) an intended way to do the above using Linq-to-Sql?

I know I can do that with 1) storproc or 2) db.ExecuteCommand("...") or 3) handle the conflict with try/catch – but I want to be sure there is no a better way.

I know it is a very basic question, but I wasn’t able to find a definite answer to this.

  • 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-18T01:03:12+00:00Added an answer on May 18, 2026 at 1:03 am

    If you are wanting to be sure that this is happening atomically in the database (regardless of what thread or application is calling it), you probably should do it in a sproc and lock at an appropriate level there. The sproc should retrieve and update the record, then release and return it (Ack! I don’t mean the TSQL return statement, but you know I mean select it, I trust!)

    So L2S just calls the sproc and gets back a task to work on, already set as Busy. L2S neither knows (nor cares) what/how things were locked – and therefore can not complicate matters and introduce more chances for deadlocks.

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

Sidebar

Related Questions

I have a table that contains tasks and I want to give these an
I have some simple shell scripting tasks that I want to do For example:
I have written a few MSBuild custom tasks that work well and are use
I have a table that contains a list of tasks; TableName: Tasks. Fields: (ID
I have a script that appends some rows to a table. One of the
I have a Tasks table something like; PK TaskId TaskName Notes ... ... FK
I have a table that records when tasks were completed. Tasks belong to a
I have a table that tracks the completion of interval tasks. for example, item
I have two tables containing Tasks and Notes, and want to retrieve a list
We have two tasks (T1 and T2) in our vxWorks embedded system that have

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.