I have a function that can be called from multiple threads that sets some
static variables. To keep things consistent I am trying to use a lock
statement. Somehow two different threads are able to get inside the lock
statement at once. Here is the code
static object checkAndWaitLockObject = new object();
private static System.Threading.ManualResetEvent mre = new
System.Threading.ManualResetEvent(true);
private volatile static int threadID;
private void CheckAndWait()
{
lock(checkAndWaitLockObject)
{
if(!context.IsTransactionPending)
{
mre.Reset();
threadID = System.Threading.Thread.CurrentThread.GetHashCode( );
return;
}
else
{
if(threadID == System.Threading.Thread.CurrentThread.GetHashCode( ))
{
return;
}
mre.WaitOne();
mre.Reset();
}
}
}
If anyone has any ideas why the lock isn't working it would be appreciated.
Thanks, Scott