I have the following scenario:
A thread pool of 3 threads, and each one of them should pick from a list of 9 operations randomly. Between that nine operations there are two which can't be performed at the same time, so I'm using a lock in those 2 methods (operations) like below:
private Object lockThis6 = new Object();
private Object lockThis7 = new Object();
public void OpSix(uSupervisor supervisor)
{
lock (lockThis6)
{
try
{
//Intructions
//Event Handler
OnOpFinished(supervisor);
}
catch
{
}
}
}
public void OpSeven(uSupervisor supervisor)
{
lock (lockThis7)
{
try
{
//Intructions
//Event Handler
OnOpFinished(supervisor);
}
catch
{
}
}
}
//EventHandler
protected virtual void OnOpFinished(uSupervisor supervisor)
{
if (OpFinished != null)
OpFinished(this, new EventLoad(supervisor));
}
In the end of the Instruction, an event is raised to "Inform" the thread to pick an operation randomly. Misteriously sometimes the Threads are getting stuck in the lock statement, I was trying to figure it out if it's a dead lock scenario but It's not the case