Lets take the sample class SomeThread where we are attempting to prevent the DoSomething methods from being called after the Running property is set to false and Dispose is
Check Running again inside the lock:
Running
while (Running) { lock(locker) { if(Running) { DoSomething1(); DoSomething2(); } } }
You could even rewrite this as a while(true)...break, which would probably be preferable.
while(true)...break