internal void EventReady(InstancePersistenceEvent persistenceEvent)
        {
            WaitForEventsAsyncResult resultToComplete = null;

            lock (ThisLock)
            {
                if (_waitResult != null)
                {
                    resultToComplete = _waitResult;
                    _waitResult      = null;
                }
            }

            if (resultToComplete != null)
            {
                resultToComplete.Signaled(persistenceEvent);
            }
        }
 private List<InstancePersistenceEvent> StartWaiting(WaitForEventsAsyncResult result, IOThreadTimer timeoutTimer, TimeSpan timeout)
 {
     lock (this.ThisLock)
     {
         if (this.waitResult != null)
         {
             throw Fx.Exception.AsError(new InvalidOperationException(SRCore.WaitAlreadyInProgress));
         }
         if (!this.IsValid)
         {
             throw Fx.Exception.AsError(new OperationCanceledException(SRCore.HandleFreed));
         }
         if ((this.boundOwnerEvents != null) && (this.boundOwnerEvents.Count > 0))
         {
             List<InstancePersistenceEvent> list = this.Store.SelectSignaledEvents(this.boundOwnerEvents, this.Owner);
             if (list != null)
             {
                 return list;
             }
         }
         this.waitResult = result;
         if (timeoutTimer != null)
         {
             timeoutTimer.Set(timeout);
         }
         return null;
     }
 }
 public void Free()
 {
     if (!this.providerObjectSet)
     {
         throw Fx.Exception.AsError(new InvalidOperationException(SRCore.HandleFreedBeforeInitialized));
     }
     if (this.IsValid)
     {
         List<InstanceHandleReference> handlesPendingResolution = null;
         WaitForEventsAsyncResult waitResult = null;
         try
         {
             bool flag = false;
             InstancePersistenceContext currentExecutionContext = null;
             lock (this.ThisLock)
             {
                 if (!this.IsValid)
                 {
                     return;
                 }
                 this.IsValid = false;
                 IEnumerable<XName> first = null;
                 if ((this.pendingOwnerEvents != null) && (this.pendingOwnerEvents.Count > 0))
                 {
                     first = from persistenceEvent in this.pendingOwnerEvents select persistenceEvent.Name;
                 }
                 if ((this.boundOwnerEvents != null) && (this.boundOwnerEvents.Count > 0))
                 {
                     first = (first == null) ? this.boundOwnerEvents : first.Concat<XName>(this.boundOwnerEvents);
                 }
                 if (first != null)
                 {
                     this.Store.RemoveHandleFromEvents(this, first, this.Owner);
                 }
                 if (this.waitResult != null)
                 {
                     waitResult = this.waitResult;
                     this.waitResult = null;
                 }
                 if (this.OperationPending)
                 {
                     if (this.AcquirePending != null)
                     {
                         this.CurrentTransactionalAsyncResult.WaitForHostTransaction.Set();
                         this.needFreedNotification = true;
                     }
                     else
                     {
                         currentExecutionContext = this.CurrentExecutionContext;
                     }
                 }
                 else
                 {
                     flag = true;
                     if (this.inProgressBind != null)
                     {
                         this.Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
                     }
                     else if (this.Version != -1L)
                     {
                         this.Owner.Unbind(this);
                     }
                 }
             }
             if (currentExecutionContext != null)
             {
                 currentExecutionContext.NotifyHandleFree();
                 lock (this.ThisLock)
                 {
                     if (this.OperationPending)
                     {
                         this.needFreedNotification = true;
                         if (this.inProgressBind != null)
                         {
                             this.Owner.FaultBind(ref this.inProgressBind, ref handlesPendingResolution, null);
                         }
                     }
                     else
                     {
                         flag = true;
                     }
                 }
             }
             if (flag)
             {
                 this.Store.FreeInstanceHandle(this, this.ProviderObject);
             }
         }
         finally
         {
             if (waitResult != null)
             {
                 waitResult.Canceled();
             }
             InstanceOwner.ResolveHandles(handlesPendingResolution);
         }
     }
 }
 internal void EventReady(InstancePersistenceEvent persistenceEvent)
 {
     WaitForEventsAsyncResult waitResult = null;
     lock (this.ThisLock)
     {
         if (this.waitResult != null)
         {
             waitResult = this.waitResult;
             this.waitResult = null;
         }
     }
     if (waitResult != null)
     {
         waitResult.Signaled(persistenceEvent);
     }
 }
 internal InstanceView Commit(InstanceView newState)
 {
     InstanceView view;
     newState.MakeReadOnly();
     this.View = newState;
     List<InstanceHandleReference> handlesPendingResolution = null;
     InstanceHandle handleToFree = null;
     List<InstancePersistenceEvent> persistenceEvents = null;
     WaitForEventsAsyncResult waitResult = null;
     try
     {
         lock (this.ThisLock)
         {
             if (this.inProgressBind != null)
             {
                 if (this.Version != -1L)
                 {
                     if (!this.Owner.TryCompleteBind(ref this.inProgressBind, ref handlesPendingResolution, out handleToFree))
                     {
                         return null;
                     }
                 }
                 else
                 {
                     this.Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
                 }
             }
             if ((this.pendingOwnerEvents != null) && this.IsValid)
             {
                 if (this.boundOwnerEvents == null)
                 {
                     this.boundOwnerEvents = new HashSet<XName>();
                 }
                 foreach (InstancePersistenceEvent event2 in this.pendingOwnerEvents)
                 {
                     if (this.boundOwnerEvents.Add(event2.Name))
                     {
                         InstancePersistenceEvent item = this.Store.AddHandleToEvent(this, event2, this.Owner);
                         if (item != null)
                         {
                             if (persistenceEvents == null)
                             {
                                 persistenceEvents = new List<InstancePersistenceEvent>(this.pendingOwnerEvents.Count);
                             }
                             persistenceEvents.Add(item);
                         }
                     }
                 }
                 this.pendingOwnerEvents = null;
                 if ((persistenceEvents != null) && (this.waitResult != null))
                 {
                     waitResult = this.waitResult;
                     this.waitResult = null;
                 }
             }
             view = this.View;
         }
     }
     finally
     {
         InstanceOwner.ResolveHandles(handlesPendingResolution);
         if (handleToFree != null)
         {
             handleToFree.Free();
         }
         if (waitResult != null)
         {
             waitResult.Signaled(persistenceEvents);
         }
     }
     return view;
 }
 private bool CancelWaiting(WaitForEventsAsyncResult result)
 {
     lock (this.ThisLock)
     {
         if (!object.ReferenceEquals(this.waitResult, result))
         {
             return false;
         }
         this.waitResult = null;
         return true;
     }
 }
Beispiel #7
0
 internal static List <InstancePersistenceEvent> EndWaitForEvents(IAsyncResult result)
 {
     return(WaitForEventsAsyncResult.End(result));
 }
Beispiel #8
0
        // Returns null if an InstanceHandleConflictException should be thrown.
        internal InstanceView Commit(InstanceView newState)
        {
            Fx.Assert(newState != null, "Null view passed to Commit.");
            newState.MakeReadOnly();
            View = newState;

            List <InstanceHandleReference> handlesPendingResolution = null;
            InstanceHandle handleToFree                      = null;
            List <InstancePersistenceEvent> normals          = null;
            WaitForEventsAsyncResult        resultToComplete = null;

            try
            {
                lock (ThisLock)
                {
                    if (this.inProgressBind != null)
                    {
                        // If there's a Version, it should be committed.
                        if (Version != -1)
                        {
                            if (!Owner.TryCompleteBind(ref this.inProgressBind, ref handlesPendingResolution, out handleToFree))
                            {
                                return(null);
                            }
                        }
                        else
                        {
                            Fx.Assert(OperationPending, "Should have cancelled this bind in FinishOperation.");
                            Fx.Assert(AcquirePending == null, "Should not be in Commit during AcquirePending.");
                            Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
                        }
                    }

                    if (this.pendingOwnerEvents != null && IsValid)
                    {
                        if (this.boundOwnerEvents == null)
                        {
                            this.boundOwnerEvents = new HashSet <XName>();
                        }

                        foreach (InstancePersistenceEvent persistenceEvent in this.pendingOwnerEvents)
                        {
                            if (!this.boundOwnerEvents.Add(persistenceEvent.Name))
                            {
                                Fx.Assert("Should not have conflicts between pending and bound events.");
                                continue;
                            }

                            InstancePersistenceEvent normal = Store.AddHandleToEvent(this, persistenceEvent, Owner);
                            if (normal != null)
                            {
                                if (normals == null)
                                {
                                    normals = new List <InstancePersistenceEvent>(this.pendingOwnerEvents.Count);
                                }
                                normals.Add(normal);
                            }
                        }

                        this.pendingOwnerEvents = null;

                        if (normals != null && this.waitResult != null)
                        {
                            resultToComplete = this.waitResult;
                            this.waitResult  = null;
                        }
                    }

                    return(View);
                }
            }
            finally
            {
                InstanceOwner.ResolveHandles(handlesPendingResolution);

                // This is a convenience, it is not required for correctness.
                if (handleToFree != null)
                {
                    Fx.Assert(!object.ReferenceEquals(handleToFree, this), "Shouldn't have been told to free ourselves.");
                    handleToFree.Free();
                }

                if (resultToComplete != null)
                {
                    resultToComplete.Signaled(normals);
                }
            }
        }
Beispiel #9
0
        public void Free()
        {
            if (!this.providerObjectSet)
            {
                throw Fx.Exception.AsError(new InvalidOperationException(SRCore.HandleFreedBeforeInitialized));
            }

            if (!IsValid)
            {
                return;
            }

            List <InstanceHandleReference> handlesPendingResolution = null;
            WaitForEventsAsyncResult       resultToCancel           = null;

            try
            {
                bool needNotification = false;
                InstancePersistenceContext currentContext = null;

                lock (ThisLock)
                {
                    if (!IsValid)
                    {
                        return;
                    }
                    IsValid = false;

                    IEnumerable <XName> eventsToUnbind = null;
                    if (this.pendingOwnerEvents != null && this.pendingOwnerEvents.Count > 0)
                    {
                        eventsToUnbind = this.pendingOwnerEvents.Select(persistenceEvent => persistenceEvent.Name);
                    }
                    if (this.boundOwnerEvents != null && this.boundOwnerEvents.Count > 0)
                    {
                        eventsToUnbind = eventsToUnbind == null ? this.boundOwnerEvents : eventsToUnbind.Concat(this.boundOwnerEvents);
                    }
                    if (eventsToUnbind != null)
                    {
                        Fx.Assert(Owner != null, "How do we have owner events without an owner.");
                        Store.RemoveHandleFromEvents(this, eventsToUnbind, Owner);
                    }
                    if (this.waitResult != null)
                    {
                        resultToCancel  = this.waitResult;
                        this.waitResult = null;
                    }

                    if (OperationPending)
                    {
                        if (AcquirePending != null)
                        {
                            // If in this stage, we need to short-circuit the pending transaction.
                            Fx.Assert(CurrentTransactionalAsyncResult != null, "Should have a pending transaction if we are waiting for it.");
                            CurrentTransactionalAsyncResult.WaitForHostTransaction.Set();
                            this.needFreedNotification = true;
                        }
                        else
                        {
                            // Here, just notify the currently executing command.
                            Fx.Assert(CurrentExecutionContext != null, "Must have either this or AcquirePending set.");
                            currentContext = CurrentExecutionContext;
                        }
                    }
                    else
                    {
                        needNotification = true;

                        if (this.inProgressBind != null)
                        {
                            Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
                        }
                        else if (Version != -1)
                        {
                            // This means the handle was successfully bound in the past.  Need to remove it from the table of handles.
                            Owner.Unbind(this);
                        }
                    }
                }

                if (currentContext != null)
                {
                    // Need to do this not in a lock.
                    currentContext.NotifyHandleFree();

                    lock (ThisLock)
                    {
                        if (OperationPending)
                        {
                            this.needFreedNotification = true;

                            // Cancel any pending lock reclaim here.
                            if (this.inProgressBind != null)
                            {
                                Fx.Assert(Owner != null, "Must be bound to owner to have an inProgressBind for the lock in CancelReclaim.");

                                // Null reason defaults to OperationCanceledException.  (Defer creating it since this might not be a
                                // reclaim attempt, but we don't know until we take the HandlesLock.)
                                Owner.FaultBind(ref this.inProgressBind, ref handlesPendingResolution, null);
                            }
                        }
                        else
                        {
                            needNotification = true;
                        }
                    }
                }

                if (needNotification)
                {
                    Store.FreeInstanceHandle(this, ProviderObject);
                }
            }
            finally
            {
                if (resultToCancel != null)
                {
                    resultToCancel.Canceled();
                }

                InstanceOwner.ResolveHandles(handlesPendingResolution);
            }
        }
Beispiel #10
0
        internal void EventReady(InstancePersistenceEvent persistenceEvent)
        {
            WaitForEventsAsyncResult resultToComplete = null;
            lock (ThisLock)
            {
                if (this.waitResult != null)
                {
                    resultToComplete = this.waitResult;
                    this.waitResult = null;
                }
            }

            if (resultToComplete != null)
            {
                resultToComplete.Signaled(persistenceEvent);
            }
        }
Beispiel #11
0
 bool CancelWaiting(WaitForEventsAsyncResult result)
 {
     lock (ThisLock)
     {
         Fx.Assert(result != null, "Null result passed to CancelWaiting.");
         if (!object.ReferenceEquals(this.waitResult, result))
         {
             return false;
         }
         this.waitResult = null;
         return true;
     }
 }
Beispiel #12
0
        List<InstancePersistenceEvent> StartWaiting(WaitForEventsAsyncResult result, IOThreadTimer timeoutTimer, TimeSpan timeout)
        {
            lock (ThisLock)
            {
                if (this.waitResult != null)
                {
                    throw Fx.Exception.AsError(new InvalidOperationException(SRCore.WaitAlreadyInProgress));
                }
                if (!IsValid)
                {
                    throw Fx.Exception.AsError(new OperationCanceledException(SRCore.HandleFreed));
                }

                if (this.boundOwnerEvents != null && this.boundOwnerEvents.Count > 0)
                {
                    Fx.Assert(Owner != null, "How do we have owner events without an owner.");
                    List<InstancePersistenceEvent> readyEvents = Store.SelectSignaledEvents(this.boundOwnerEvents, Owner);
                    if (readyEvents != null)
                    {
                        Fx.Assert(readyEvents.Count != 0, "Should not return a zero-length list.");
                        return readyEvents;
                    }
                }

                this.waitResult = result;

                // This is done here to be under the lock.  That way it doesn't get canceled before it is set.
                if (timeoutTimer != null)
                {
                    timeoutTimer.Set(timeout);
                }

                return null;
            }
        }
Beispiel #13
0
        // Returns null if an InstanceHandleConflictException should be thrown.
        internal InstanceView Commit(InstanceView newState)
        {
            Fx.Assert(newState != null, "Null view passed to Commit.");
            newState.MakeReadOnly();
            View = newState;

            List<InstanceHandleReference> handlesPendingResolution = null;
            InstanceHandle handleToFree = null;
            List<InstancePersistenceEvent> normals = null;
            WaitForEventsAsyncResult resultToComplete = null;
            try
            {
                lock (ThisLock)
                {
                    if (this.inProgressBind != null)
                    {
                        // If there's a Version, it should be committed.
                        if (Version != -1)
                        {
                            if (!Owner.TryCompleteBind(ref this.inProgressBind, ref handlesPendingResolution, out handleToFree))
                            {
                                return null;
                            }
                        }
                        else
                        {
                            Fx.Assert(OperationPending, "Should have cancelled this bind in FinishOperation.");
                            Fx.Assert(AcquirePending == null, "Should not be in Commit during AcquirePending.");
                            Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
                        }
                    }

                    if (this.pendingOwnerEvents != null && IsValid)
                    {
                        if (this.boundOwnerEvents == null)
                        {
                            this.boundOwnerEvents = new HashSet<XName>();
                        }

                        foreach (InstancePersistenceEvent persistenceEvent in this.pendingOwnerEvents)
                        {
                            if (!this.boundOwnerEvents.Add(persistenceEvent.Name))
                            {
                                Fx.Assert("Should not have conflicts between pending and bound events.");
                                continue;
                            }

                            InstancePersistenceEvent normal = Store.AddHandleToEvent(this, persistenceEvent, Owner);
                            if (normal != null)
                            {
                                if (normals == null)
                                {
                                    normals = new List<InstancePersistenceEvent>(this.pendingOwnerEvents.Count);
                                }
                                normals.Add(normal);
                            }
                        }

                        this.pendingOwnerEvents = null;

                        if (normals != null && this.waitResult != null)
                        {
                            resultToComplete = this.waitResult;
                            this.waitResult = null;
                        }
                    }

                    return View;
                }
            }
            finally
            {
                InstanceOwner.ResolveHandles(handlesPendingResolution);

                // This is a convenience, it is not required for correctness.
                if (handleToFree != null)
                {
                    Fx.Assert(!object.ReferenceEquals(handleToFree, this), "Shouldn't have been told to free ourselves.");
                    handleToFree.Free();
                }

                if (resultToComplete != null)
                {
                    resultToComplete.Signaled(normals);
                }
            }
        }
Beispiel #14
0
        public void Free()
        {
            if (!this.providerObjectSet)
            {
                throw Fx.Exception.AsError(new InvalidOperationException(SRCore.HandleFreedBeforeInitialized));
            }

            if (!IsValid)
            {
                return;
            }

            List<InstanceHandleReference> handlesPendingResolution = null;
            WaitForEventsAsyncResult resultToCancel = null;

            try
            {
                bool needNotification = false;
                InstancePersistenceContext currentContext = null;

                lock (ThisLock)
                {
                    if (!IsValid)
                    {
                        return;
                    }
                    IsValid = false;

                    IEnumerable<XName> eventsToUnbind = null;
                    if (this.pendingOwnerEvents != null && this.pendingOwnerEvents.Count > 0)
                    {
                        eventsToUnbind = this.pendingOwnerEvents.Select(persistenceEvent => persistenceEvent.Name);
                    }
                    if (this.boundOwnerEvents != null && this.boundOwnerEvents.Count > 0)
                    {
                        eventsToUnbind = eventsToUnbind == null ? this.boundOwnerEvents : eventsToUnbind.Concat(this.boundOwnerEvents);
                    }
                    if (eventsToUnbind != null)
                    {
                        Fx.Assert(Owner != null, "How do we have owner events without an owner.");
                        Store.RemoveHandleFromEvents(this, eventsToUnbind, Owner);
                    }
                    if (this.waitResult != null)
                    {
                        resultToCancel = this.waitResult;
                        this.waitResult = null;
                    }

                    if (OperationPending)
                    {
                        if (AcquirePending != null)
                        {
                            // If in this stage, we need to short-circuit the pending transaction.
                            Fx.Assert(CurrentTransactionalAsyncResult != null, "Should have a pending transaction if we are waiting for it.");
                            CurrentTransactionalAsyncResult.WaitForHostTransaction.Set();
                            this.needFreedNotification = true;
                        }
                        else
                        {
                            // Here, just notify the currently executing command.
                            Fx.Assert(CurrentExecutionContext != null, "Must have either this or AcquirePending set.");
                            currentContext = CurrentExecutionContext;
                        }
                    }
                    else
                    {
                        needNotification = true;

                        if (this.inProgressBind != null)
                        {
                            Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
                        }
                        else if (Version != -1)
                        {
                            // This means the handle was successfully bound in the past.  Need to remove it from the table of handles.
                            Owner.Unbind(this);
                        }
                    }
                }

                if (currentContext != null)
                {
                    // Need to do this not in a lock.
                    currentContext.NotifyHandleFree();

                    lock (ThisLock)
                    {
                        if (OperationPending)
                        {
                            this.needFreedNotification = true;

                            // Cancel any pending lock reclaim here.
                            if (this.inProgressBind != null)
                            {
                                Fx.Assert(Owner != null, "Must be bound to owner to have an inProgressBind for the lock in CancelReclaim.");

                                // Null reason defaults to OperationCanceledException.  (Defer creating it since this might not be a
                                // reclaim attempt, but we don't know until we take the HandlesLock.)
                                Owner.FaultBind(ref this.inProgressBind, ref handlesPendingResolution, null);
                            }
                        }
                        else
                        {
                            needNotification = true;
                        }
                    }
                }

                if (needNotification)
                {
                    Store.FreeInstanceHandle(this, ProviderObject);
                }
            }
            finally
            {
                if (resultToCancel != null)
                {
                    resultToCancel.Canceled();
                }

                InstanceOwner.ResolveHandles(handlesPendingResolution);
            }
        }
Beispiel #15
0
 public void Free()
 {
     if (!this.providerObjectSet)
     {
         throw Fx.Exception.AsError(new InvalidOperationException(SRCore.HandleFreedBeforeInitialized));
     }
     if (this.IsValid)
     {
         List <InstanceHandleReference> handlesPendingResolution = null;
         WaitForEventsAsyncResult       waitResult = null;
         try
         {
             bool flag = false;
             InstancePersistenceContext currentExecutionContext = null;
             lock (this.ThisLock)
             {
                 if (!this.IsValid)
                 {
                     return;
                 }
                 this.IsValid = false;
                 IEnumerable <XName> first = null;
                 if ((this.pendingOwnerEvents != null) && (this.pendingOwnerEvents.Count > 0))
                 {
                     first = from persistenceEvent in this.pendingOwnerEvents select persistenceEvent.Name;
                 }
                 if ((this.boundOwnerEvents != null) && (this.boundOwnerEvents.Count > 0))
                 {
                     first = (first == null) ? this.boundOwnerEvents : first.Concat <XName>(this.boundOwnerEvents);
                 }
                 if (first != null)
                 {
                     this.Store.RemoveHandleFromEvents(this, first, this.Owner);
                 }
                 if (this.waitResult != null)
                 {
                     waitResult      = this.waitResult;
                     this.waitResult = null;
                 }
                 if (this.OperationPending)
                 {
                     if (this.AcquirePending != null)
                     {
                         this.CurrentTransactionalAsyncResult.WaitForHostTransaction.Set();
                         this.needFreedNotification = true;
                     }
                     else
                     {
                         currentExecutionContext = this.CurrentExecutionContext;
                     }
                 }
                 else
                 {
                     flag = true;
                     if (this.inProgressBind != null)
                     {
                         this.Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
                     }
                     else if (this.Version != -1L)
                     {
                         this.Owner.Unbind(this);
                     }
                 }
             }
             if (currentExecutionContext != null)
             {
                 currentExecutionContext.NotifyHandleFree();
                 lock (this.ThisLock)
                 {
                     if (this.OperationPending)
                     {
                         this.needFreedNotification = true;
                         if (this.inProgressBind != null)
                         {
                             this.Owner.FaultBind(ref this.inProgressBind, ref handlesPendingResolution, null);
                         }
                     }
                     else
                     {
                         flag = true;
                     }
                 }
             }
             if (flag)
             {
                 this.Store.FreeInstanceHandle(this, this.ProviderObject);
             }
         }
         finally
         {
             if (waitResult != null)
             {
                 waitResult.Canceled();
             }
             InstanceOwner.ResolveHandles(handlesPendingResolution);
         }
     }
 }
Beispiel #16
0
        internal InstanceView Commit(InstanceView newState)
        {
            InstanceView view;

            newState.MakeReadOnly();
            this.View = newState;
            List <InstanceHandleReference> handlesPendingResolution = null;
            InstanceHandle handleToFree = null;
            List <InstancePersistenceEvent> persistenceEvents = null;
            WaitForEventsAsyncResult        waitResult        = null;

            try
            {
                lock (this.ThisLock)
                {
                    if (this.inProgressBind != null)
                    {
                        if (this.Version != -1L)
                        {
                            if (!this.Owner.TryCompleteBind(ref this.inProgressBind, ref handlesPendingResolution, out handleToFree))
                            {
                                return(null);
                            }
                        }
                        else
                        {
                            this.Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
                        }
                    }
                    if ((this.pendingOwnerEvents != null) && this.IsValid)
                    {
                        if (this.boundOwnerEvents == null)
                        {
                            this.boundOwnerEvents = new HashSet <XName>();
                        }
                        foreach (InstancePersistenceEvent event2 in this.pendingOwnerEvents)
                        {
                            if (this.boundOwnerEvents.Add(event2.Name))
                            {
                                InstancePersistenceEvent item = this.Store.AddHandleToEvent(this, event2, this.Owner);
                                if (item != null)
                                {
                                    if (persistenceEvents == null)
                                    {
                                        persistenceEvents = new List <InstancePersistenceEvent>(this.pendingOwnerEvents.Count);
                                    }
                                    persistenceEvents.Add(item);
                                }
                            }
                        }
                        this.pendingOwnerEvents = null;
                        if ((persistenceEvents != null) && (this.waitResult != null))
                        {
                            waitResult      = this.waitResult;
                            this.waitResult = null;
                        }
                    }
                    view = this.View;
                }
            }
            finally
            {
                InstanceOwner.ResolveHandles(handlesPendingResolution);
                if (handleToFree != null)
                {
                    handleToFree.Free();
                }
                if (waitResult != null)
                {
                    waitResult.Signaled(persistenceEvents);
                }
            }
            return(view);
        }