Thanks to everyone for your helpful info.
You guys are right that my statement 'only locks the current thread'
makes no sense. I was going to add that as part of my question.. the
fact that i didn't understand even the meaning of that. 'locking'
*means* locking for other threads..., you are right.
Someone at work told me this. But thinking about it what I think she
told me was that this lock statement was in an object that was not a
Singleton.. different threads were making their own instance of of
this object, and that therefore the lock was basically doing nothing.
Because it would only block other threads attempting to get inside that
code from the same instance of that object in which the lock statement
resides.
Is she right and if so, how can I lock the other threads?
Thanks again!!
Jeff
On Jan 24, 1:37 pm, "Robson Siqueira" <rob...@robsonfelix.comwrote:
Jeff,
Why don't you create a member which you can use to lock? You could use
Interlocked class, ReadWriterLock class, Monitor class, etc, to manipulate
this object. Even using just lock would work.
Best,
--
Regards,
Robson Siqueira
Enterprise Architect<jeff.ran...@gmail.comwrote in messagenews:11**********************@q2g2000cwa.go oglegroups.com...
Hi all.
I wrote this C# code:
lock(this)
{
/ /write to a file
}
thinking that it was going to make other threads wait in line to access
the same block of code. But as I now understand it this only locks the
current thread.
Does anyone know if there a way to do what I was originally intending?
- stop other threads from simultaneously accessing the code inside a
given block?
Thanks,
Jeff- Hide quoted text -- Show quoted text -