I have used the lock statement in C# to exclusively execute a piece of code. Is there a way to do same based on a key.
for e.g.:
lock(object, key)
{
//code-here
}
I have a method which has some piece of code that is not thread-safe, but only if the key (string) happens to be same in two parallel executions. Is there a way to somehow accomplish this in .NET ?
If there is a way then we can have parallel executions if the key being used in the parallel executions is different and could improve performance.