I have to organize thread safe removing of items from collection, with using anonymous method. Something like this.
...
lock(this.set)
{
...
this.set.Add(item);
action(()=>{
lock(this.set)
{
this.set.Remove(item);
}
});
}
...
Anonymous method will be executed by the time, probably, from another thread. Is this way of lock operators correct? Is there are some riffs i have to take into account here?
Thanks in advance.
This will work however, have you looked at the ConcurrentCollections in .NET 4? They are internally threadsafe