It depends on what you mean by rows. If by rows you mean an in memory
data structure, then yes, a lock statement will help in this case.
However, if you are updating an underlying data store of some sort, then
you might have to do something different. For example, if you were updating
rows in a database, then you would have to wrap the whole thing in a
transaction. If you were updating a file, you would have to open it with
exclusive access, and use the lock statement as well, as I believe that the
exclusive access is for a process (and you mentioned multiple threads
hitting this routine).
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
<ri**************@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
Hi,
I have a static method that I use for data access. This particular
method reads x number of rows and then updates these rows with a read
= 1 flag. I access this method with several threads and I guess that
one thread (thread A) could read rows and then the next thread (thread
B) would read the same rows BEFORE the first thread has updated
"it's" (all the rows selected by thread A) rows as read - right? Will
it help just wrapping this complete method (the one that read and then
updates the rows as read) in a lock or is that unnecessary in this
case?