Код: Выделить всё
try { }
finally
{
lockTaken = false; // reset lockTaken to avoid calling Monitor.Exit again in the finally block
Monitor.Exit(list);
}
Код: Выделить всё
bool lockTaken = false;
try
{
Monitor.Enter(obj, ref lockTaken);
// some code here
}
finally
{
if (lockTaken)
{
Monitor.Exit(obj);
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... nstruction
Мобильная версия