private bool OpenProvider()
 {
     if (this.operation == WorkflowServiceInstance.PersistenceOperation.Unload)
     {
         if (((this.instance.state != WorkflowServiceInstance.State.Suspended) && !this.instance.IsIdle) && this.isTry)
         {
             this.tryResult = false;
             return true;
         }
         if (!this.instance.TryReleaseLastReference() && this.isTry)
         {
             this.tryResult = false;
             return true;
         }
     }
     if ((this.operation == WorkflowServiceInstance.PersistenceOperation.Unload) && (this.instance.Controller.State == WorkflowInstanceState.Complete))
     {
         this.operation = WorkflowServiceInstance.PersistenceOperation.Delete;
     }
     bool flag = false;
     if ((this.instance.persistenceContext != null) && (this.instance.persistenceContext.State == CommunicationState.Created))
     {
         IAsyncResult result = this.instance.persistenceContext.BeginOpen(this.timeoutHelper.RemainingTime(), this.PrepareInnerAsyncCompletion(providerOpenedCallback), this);
         if (result.CompletedSynchronously)
         {
             flag = OnProviderOpened(result);
         }
         return flag;
     }
     return this.Track();
 }
 public UnloadOrPersistAsyncResult(WorkflowServiceInstance instance, WorkflowServiceInstance.PersistenceOperation operation, bool isWorkflowThread, bool isTry, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.instance = instance;
     this.timeoutHelper = new TimeoutHelper(timeout);
     this.operation = operation;
     this.isWorkflowThread = isWorkflowThread;
     this.isTry = isTry;
     this.tryResult = true;
     this.isUnloaded = (operation == WorkflowServiceInstance.PersistenceOperation.Unload) || (operation == WorkflowServiceInstance.PersistenceOperation.Delete);
     this.saveStatus = SaveStatus.Locked;
     this.isCompletionTransactionRequired = ((this.isUnloaded && (instance.Controller.State == WorkflowInstanceState.Complete)) && (instance.creationContext != null)) && instance.creationContext.IsCompletionTransactionRequired;
     this.isIdlePolicyPersist = isTry && (operation == WorkflowServiceInstance.PersistenceOperation.Save);
     if (operation == WorkflowServiceInstance.PersistenceOperation.Unload)
     {
         this.saveStatus = SaveStatus.Unlocked;
     }
     else if (operation == WorkflowServiceInstance.PersistenceOperation.Delete)
     {
         this.saveStatus = SaveStatus.Completed;
     }
     Transaction current = Transaction.Current;
     if (current != null)
     {
         base.OnCompleting = completeCallback;
         this.dependentTransaction = current.DependentClone(DependentCloneOption.BlockCommitUntilComplete);
     }
     bool flag = true;
     bool flag2 = false;
     try
     {
         if (this.isWorkflowThread)
         {
             flag = this.OpenProvider();
         }
         else
         {
             try
             {
                 flag = this.LockAndPassGuard();
             }
             finally
             {
                 if (flag)
                 {
                     this.instance.ReleaseLock(ref this.ownsLock, this.isIdlePolicyPersist);
                 }
             }
         }
         flag2 = true;
     }
     finally
     {
         if (!flag2 && (this.dependentTransaction != null))
         {
             this.dependentTransaction.Complete();
         }
     }
     if (flag)
     {
         base.Complete(true);
     }
 }