In .Net4, Monitor.Enter (Object) is marked obsolete:
[ObsoleteAttribute("This method does not allow its caller to reliably release the lock. Please use an overload with a lockTaken argument instead.")]
public static void Enter(
Object obj
)
And there is a new Monitor.Enter method (lockObject acquired by Lock) with this use:
bool acquiredLock = false;
try
{
Monitor.Enter(lockObject, ref acquiredLock);
}
finally
{
if (acquiredLock)
{
Monitor.Exit(lockObject);
}
}
I did it like this:
Monitor.Enter(lockObject);
try
{
}
finally
{
Monitor.Exit(lockObject);
}
It is not right? What for? Maybe with interupt after login, but before trying?
As Eamon Nerbonn wrote: what happens if an asynchronous exception eventually occurs before monitor.exit?
Answer: ThreadAbortException
When this exception is raised, runtime executes all final blocks before terminating the thread.
source
share