locking rows in a multithreaded application
-
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.
-
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.
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