If i have an function that edits the database in my webservice that i only want one thread to execute at one time if they try to edit the same row.
void Edit
You can use a ConcurrentDictionary
to map each id to an object that you can lock on:
public class Foo
{
private ConcurrentDictionary dictionary =
new ConcurrentDictionary();
private void EditCheck(long checkid)
{
var key = dictionary.GetOrAdd(checkid, new object());
lock (key)
{
//Do stuff with key
}
}
}