internal void FaultBind(ref InstanceHandleReference reference, ref List <InstanceHandleReference> handlesPendingResolution, Exception reason)
        {
            Fx.Assert(reference != null, "Bind not in progress in FaultBind.");
            Fx.Assert(reference.InstanceHandle != null, "Reference already canceled in FaultBind.");
            Fx.Assert(object.ReferenceEquals(this, reference.InstanceHandle.Owner), "FaultBind called on the wrong owner for a handle.");

            lock (HandlesLock)
            {
                LockResolutionMarker marker = reference as LockResolutionMarker;
                if (marker != null && !marker.IsComplete)
                {
                    try
                    {
                        // Nothing to do here - following the patterns of dealing with handlesPendingResolution and setting NotifyMarkerComplete in a finally.
                    }
                    finally
                    {
                        marker.Reason = reason ?? new OperationCanceledException(SRCore.HandleFreed);
                        marker.NotifyMarkerComplete(false);

                        if (handlesPendingResolution == null)
                        {
                            handlesPendingResolution = new List <InstanceHandleReference>(1);
                        }
                        handlesPendingResolution.Add(marker);
                    }
                }
            }
        }
        // Must be called with HandlesLock held.
        // This is called when a reference becomes the oldest in-progress reference for an instance.  This triggers the end of resolution for markers.
        // Returns false if the resolution failed, meaning that the marker can be removed.
        bool CheckOldestReference(InstanceHandleReference handleRef, ref List <InstanceHandleReference> handlesPendingResolution)
        {
            LockResolutionMarker marker = handleRef as LockResolutionMarker;

            if (marker == null || marker.IsComplete)
            {
                return(true);
            }

            bool returnValue = true;

            try
            {
                InstanceHandle existingHandle;
                if (BoundHandles.TryGetValue(marker.InstanceHandle.Id, out existingHandle))
                {
                    Fx.AssertAndFailFast(!object.ReferenceEquals(existingHandle, marker.InstanceHandle), "InstanceStore lock state is not correct in CheckOldestReference.");
                    if (existingHandle.Version <= 0 || marker.InstanceVersion <= 0)
                    {
                        if (existingHandle.Version != 0 || marker.InstanceVersion != 0)
                        {
                            marker.Reason = new InvalidOperationException(SRCore.InvalidLockToken);
                            returnValue   = false;
                        }
                        else
                        {
                            marker.ConflictingHandle = existingHandle;
                            returnValue = false;
                        }
                    }
                    else if (existingHandle.Version >= marker.InstanceVersion)
                    {
                        marker.ConflictingHandle = existingHandle;
                        returnValue = false;
                    }
                }

                // No other handles have committed a bind to this or a higher version!  We are ok to do so, but it is still not committed, so we stay in queue.
                return(returnValue);
            }
            finally
            {
                marker.NotifyMarkerComplete(returnValue);

                if (handlesPendingResolution == null)
                {
                    handlesPendingResolution = new List <InstanceHandleReference>(1);
                }
                handlesPendingResolution.Add(marker);
            }
        }
        private bool CheckOldestReference(InstanceHandleReference handleRef, ref List <InstanceHandleReference> handlesPendingResolution)
        {
            bool flag2;
            LockResolutionMarker item = handleRef as LockResolutionMarker;

            if ((item == null) || item.IsComplete)
            {
                return(true);
            }
            bool success = true;

            try
            {
                InstanceHandle handle;
                if (this.BoundHandles.TryGetValue(item.InstanceHandle.Id, out handle))
                {
                    Fx.AssertAndFailFast(!object.ReferenceEquals(handle, item.InstanceHandle), "InstanceStore lock state is not correct in CheckOldestReference.");
                    if ((handle.Version <= 0L) || (item.InstanceVersion <= 0L))
                    {
                        if ((handle.Version != 0L) || (item.InstanceVersion != 0L))
                        {
                            item.Reason = new InvalidOperationException(SRCore.InvalidLockToken);
                            success     = false;
                        }
                        else
                        {
                            item.ConflictingHandle = handle;
                            success = false;
                        }
                    }
                    else if (handle.Version >= item.InstanceVersion)
                    {
                        item.ConflictingHandle = handle;
                        success = false;
                    }
                }
                flag2 = success;
            }
            finally
            {
                item.NotifyMarkerComplete(success);
                if (handlesPendingResolution == null)
                {
                    handlesPendingResolution = new List <InstanceHandleReference>(1);
                }
                handlesPendingResolution.Add(item);
            }
            return(flag2);
        }
 internal void FaultBind(ref InstanceHandleReference reference, ref List <InstanceHandleReference> handlesPendingResolution, Exception reason)
 {
     lock (this.HandlesLock)
     {
         LockResolutionMarker item = reference as LockResolutionMarker;
         if ((item != null) && !item.IsComplete)
         {
             try
             {
             }
             finally
             {
                 item.Reason = reason ?? new OperationCanceledException(SRCore.HandleFreed);
                 item.NotifyMarkerComplete(false);
                 if (handlesPendingResolution == null)
                 {
                     handlesPendingResolution = new List <InstanceHandleReference>(1);
                 }
                 handlesPendingResolution.Add(item);
             }
         }
     }
 }