Can I overwrite an Object that has been Locked() in C#?
Posted
by
makerofthings7
on Stack Overflow
See other posts from Stack Overflow
or by makerofthings7
Published on 2011-01-16T04:39:02Z
Indexed on
2011/01/16
4:53 UTC
Read the original article
Hit count: 152
I have a few objects that I'd like to send to the server, but I want to make sure that this is the only thread that moving the data from Stage to Upload. Is the following code valid in a multithreaded environment?
List<CounterInternal> UploadToServer = new List<CounterInternal>();
List<CounterInternal> StagingQueue = new List<CounterInternal>();
lock (this.UploadToServer)
lock (this.StagingQueue)
{
if (UploadToServer.Count == 0)
{
UploadToServer = StagingQueue.DoDeepCopyExtensionMethod();
// is the following line valid given that I have a Lock() on it?
StagingQueue = new List<CounterInternal>();
}
}
}
© Stack Overflow or respective owner