private bool LockImpl(Duration timeout)
{
Debug.Assert(timeout != Duration.Automatic);
bool lockObtained = false;
if (_lockCount == UInt32.MaxValue)
{
throw new InvalidOperationException(SR.Get(SRID.Image_LockCountLimit));
}
if (_lockCount == 0)
{
if (timeout == Duration.Forever)
{
lockObtained = _canWriteEvent.WaitOne();
}
else
{
lockObtained = _canWriteEvent.WaitOne(timeout.TimeSpan, false);
}
// Consider the situation: Lock(); AddDirtyRect(); Unlock(); Lock(); return;
// The Unlock will have set us up to send a present packet but since
// the user re-locked the buffer we shouldn't copy forward
UnsubscribeFromCommittingBatch();
}
++_lockCount;
// no WritePostscript because this isn't a "change" yet
return lockObtained;
}