System.Windows.Interop.D3DImage.LockImpl C# (CSharp) Method

LockImpl() private method

Lock implementation shared by Lock and TryLock
private LockImpl ( Duration timeout ) : bool
timeout Duration
return bool
        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;
        }