Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. locking rows in a multithreaded application

locking rows in a multithreaded application

Scheduled Pinned Locked Moved C#
csharphelpannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Prashant Gadhave
    wrote on last edited by
    #1

    In a windows application(C#) I am working on,I have 5 threads accessing data from a table and running one after another.I want to lock data for each thread when it is accessing data ,so I have used "for update" in my select statement but it doesn't work.Every thread when accessing data sets one flag in the table so that other threads should not select this data again,but some times 2 or 3 threads access the same row .Any help to lock the rows please. Thank you.

    R 1 Reply Last reply
    0
    • P Prashant Gadhave

      In a windows application(C#) I am working on,I have 5 threads accessing data from a table and running one after another.I want to lock data for each thread when it is accessing data ,so I have used "for update" in my select statement but it doesn't work.Every thread when accessing data sets one flag in the table so that other threads should not select this data again,but some times 2 or 3 threads access the same row .Any help to lock the rows please. Thank you.

      R Offline
      R Offline
      Ricardo Casquete
      wrote on last edited by
      #2

      The time we have to did this, we have to create anhoter table in the database with information about the tables or rows locked. I mean. One Method to lock Lock ( string TableName ) Lock ( int[] RowsIDs ) UnLock ( string TableName ) UnLock ( int[] RowsIDs ) Write this info in a table, and when the data is queried to the database do a Join with the rows of this table. Also we add a delay of 5 minutes to set free the rows, because someone can forget the UnLock. Regards Ricardo Casquete

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups