In the class below, I have methods that do two completely different things that have nothing to do with eachother. But I use only one lock object in both of them.
My question is: what is the best practice in such scenarios? Having two separate lock objects for each or separating them (how do we do it)?
class MyClass
{
private static object _lock = new object();
public void DoSomething()
{
lock (_lock)
{
}
}
public void DoSomethingTotallyDifferent()
{
lock (_lock)
{
}
}
}
source
share