How to prevent 2 or more thread/console read the same DB record at the same time?

Last post 07-24-2009 8:22 PM by jimmy q. 1 replies.

Sort Posts:

  • How to prevent 2 or more thread/console read the same DB record at the same time?

    07-22-2009, 4:27 AM
    • Member
      92 point Member
    • enghsiang
    • Member since 06-14-2007, 5:03 AM
    • Malaysia
    • Posts 236

     i have more then 1 console that will read the event list that store at db table. once the event is trigger, the flag will be update so that other console wont read the event again. but it do happen that 2 console is reading the same event at the same time and doing duplicated work.

    any idea how to prevent this?

    C#######################################
  • Re: How to prevent 2 or more thread/console read the same DB record at the same time?

    07-24-2009, 8:22 PM
    Answer
    • All-Star
      46,188 point All-Star
    • jimmy q
    • Member since 11-02-2006, 5:01 AM
    • Australia
    • Posts 3,181
    • Moderator
      TrustedFriends-MVPs

    enghsiang:

     i have more then 1 console that will read the event list that store at db table. once the event is trigger, the flag will be update so that other console wont read the event again. but it do happen that 2 console is reading the same event at the same time and doing duplicated work.

    any idea how to prevent this?

    This is concurrency and it depends where its this code that checks for the flag/trigger?

    Is this a common service that is consumed by both the console applications, or is it within the console application itself.

    Basically, depending where the first central point is, that is where you need to lock the thread/or set up a transaction.

    Therefore, if the code is in a central service you can use .NET transactions to manage this behaviour or use your SQL to manage the transaction.

Page 1 of 1 (2 items)