WorkflowServiceInstance(Activity workflowDefinition, WorkflowIdentity definitionIdentity, Guid instanceId, WorkflowServiceHost serviceHost, PersistenceContext persistenceContext)
            : base(workflowDefinition, definitionIdentity)
        {
            this.serviceHost = serviceHost;
            this.instanceId = instanceId;
            this.persistTimeout = serviceHost.PersistTimeout;
            this.trackTimeout = serviceHost.TrackTimeout;
            this.bufferedReceiveManager = serviceHost.Extensions.Find<BufferedReceiveManager>();

            if (persistenceContext != null)
            {
                this.persistenceContext = persistenceContext;
                this.persistenceContext.Closed += this.OnPersistenceContextClosed;
            }

            this.thisLock = new object();
            this.pendingRequests = new List<WorkflowOperationContext>();
            this.executorLock = new WorkflowExecutionLock(this);
            this.activeOperationsLock = new object();
            this.acquireReferenceSemaphore = new ThreadNeutralSemaphore(1);
            this.acquireLockTimeout = TimeSpan.MaxValue;

            // Two initial references are held:
            // The first referenceCount is owned by UnloadInstancePolicy (ReleaseInstance)
            this.referenceCount = 1;
            // The second referenceCount is owned by the loader / creator of the instance.
            this.TryAddReference();
        }
 public AsyncWaiterData(WorkflowExecutionLock owner, FastAsyncCallback callback, object state, object token)
 {
     this.Owner = owner;
     this.Callback = callback;
     this.State = state;
     this.Token = token;
 }
 private WorkflowServiceInstance(Activity workflowDefinition, Guid instanceId, WorkflowServiceHost serviceHost, PersistenceContext persistenceContext) : base(workflowDefinition)
 {
     this.serviceHost = serviceHost;
     this.instanceId = instanceId;
     this.persistTimeout = serviceHost.PersistTimeout;
     this.trackTimeout = serviceHost.TrackTimeout;
     this.bufferedReceiveManager = serviceHost.Extensions.Find<System.ServiceModel.Activities.Dispatcher.BufferedReceiveManager>();
     if (persistenceContext != null)
     {
         this.persistenceContext = persistenceContext;
         this.persistenceContext.Closed += new EventHandler(this.OnPersistenceContextClosed);
     }
     this.thisLock = new object();
     this.pendingRequests = new List<WorkflowOperationContext>();
     this.executorLock = new WorkflowExecutionLock(this);
     this.activeOperationsLock = new object();
     this.acquireReferenceSemaphore = new ThreadNeutralSemaphore(1);
     this.acquireLockTimeout = TimeSpan.MaxValue;
     this.referenceCount = 1;
     this.TryAddReference();
 }