Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C# Programming

Multi threading static method and possible locking


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?

    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]
          - m@spam.guard.caspershouse.com

<richard.hallg@gmail.com> wrote in message

news:1180470103.017044.306400@p77g2000hsh.googlegroups.com...

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc