コード例 #1
0
        public bool TryEnter(TimeSpan timeout)
        {
            AsyncWaitHandle asyncWaitHandle = this.EnterCore();

            if (asyncWaitHandle == null)
            {
                return(true);
            }
            else
            {
                bool flag = !asyncWaitHandle.Wait(timeout);
                if (!this.aborted)
                {
                    if (flag && !this.RemoveWaiter(asyncWaitHandle))
                    {
                        flag = false;
                    }
                    return(!flag);
                }
                else
                {
                    throw Fx.Exception.AsError(this.CreateObjectAbortedException());
                }
            }
        }
コード例 #2
0
        public bool EnterAsync(TimeSpan timeout, FastAsyncCallback callback, object state)
        {
            bool flag;

            lock (this.ThisLock)
            {
                if (!this.aborted)
                {
                    if (this.count >= this.maxCount)
                    {
                        AsyncWaitHandle asyncWaitHandle = new AsyncWaitHandle();
                        this.Waiters.Enqueue(asyncWaitHandle);
                        return(asyncWaitHandle.WaitAsync(ThreadNeutralSemaphore.EnteredAsyncCallback, new ThreadNeutralSemaphore.EnterAsyncData(this, asyncWaitHandle, callback, state), timeout));
                    }
                    else
                    {
                        ThreadNeutralSemaphore threadNeutralSemaphore = this;
                        threadNeutralSemaphore.count = threadNeutralSemaphore.count + 1;
                        flag = true;
                    }
                }
                else
                {
                    throw Fx.Exception.AsError(this.CreateObjectAbortedException());
                }
            }
            return(flag);
        }
コード例 #3
0
        private AsyncWaitHandle EnterCore()
        {
            AsyncWaitHandle asyncWaitHandle;

            lock (this.ThisLock)
            {
                if (!this.aborted)
                {
                    if (this.count >= this.maxCount)
                    {
                        AsyncWaitHandle asyncWaitHandle1 = new AsyncWaitHandle();
                        this.Waiters.Enqueue(asyncWaitHandle1);
                        return(asyncWaitHandle1);
                    }
                    else
                    {
                        ThreadNeutralSemaphore threadNeutralSemaphore = this;
                        threadNeutralSemaphore.count = threadNeutralSemaphore.count + 1;
                        asyncWaitHandle = null;
                    }
                }
                else
                {
                    throw Fx.Exception.AsError(this.CreateObjectAbortedException());
                }
            }
            return(asyncWaitHandle);
        }
コード例 #4
0
        public bool TryEnter(TimeSpan timeout)
        {
            AsyncWaitHandle waiter = EnterCore();

            if (waiter != null)
            {
                bool timedOut = !waiter.Wait(timeout);

                if (this.aborted)
                {
                    throw Fx.Exception.AsError(CreateObjectAbortedException());
                }

                if (timedOut && !RemoveWaiter(waiter))
                {
                    // The timeout raced with Exit and exit won.
                    // We've successfully entered.

                    timedOut = false;
                }


                return(!timedOut);
            }

            return(true);
        }
コード例 #5
0
 public EnterAsyncData(ThreadNeutralSemaphore semaphore, AsyncWaitHandle waiter, FastAsyncCallback callback, object state)
 {
     this.Waiter    = waiter;
     this.Semaphore = semaphore;
     this.Callback  = callback;
     this.State     = state;
 }
コード例 #6
0
        public bool EnterAsync(TimeSpan timeout, FastAsyncCallback callback, object state)
        {
            Fx.Assert(callback != null, "must have a non-null call back for async purposes");

            AsyncWaitHandle waiter = null;

            lock (this.ThisLock)
            {
                if (this.aborted)
                {
                    throw Fx.Exception.AsError(CreateObjectAbortedException());
                }

                if (this.count < this.maxCount)
                {
                    this.count++;
                    return(true);
                }

                waiter = new AsyncWaitHandle();
                this.Waiters.Enqueue(waiter);
            }

            return(waiter.WaitAsync(EnteredAsyncCallback, new EnterAsyncData(this, waiter, callback, state), timeout));
        }
コード例 #7
0
 public void Abort()
 {
     lock (this.ThisLock)
     {
         if (!this.aborted)
         {
             this.aborted = true;
             if (this.waiters != null)
             {
                 while (this.waiters.Count > 0)
                 {
                     AsyncWaitHandle asyncWaitHandle = this.waiters.Dequeue();
                     asyncWaitHandle.Set();
                 }
             }
         }
     }
 }
コード例 #8
0
        private static void OnTimerComplete(object state)
        {
            AsyncWaitHandle.AsyncWaiter asyncWaiter = (AsyncWaitHandle.AsyncWaiter)state;
            AsyncWaitHandle             parent      = asyncWaiter.Parent;
            bool flag = false;

            lock (parent.syncObject)
            {
                if (parent.asyncWaiters != null && parent.asyncWaiters.Remove(asyncWaiter))
                {
                    asyncWaiter.TimedOut = true;
                }
            }
            asyncWaiter.CancelTimer();
            if (flag)
            {
                asyncWaiter.Call();
            }
        }
 public bool EnterAsync(TimeSpan timeout, FastAsyncCallback callback, object state)
 {
     AsyncWaitHandle item = null;
     lock (this.ThisLock)
     {
         if (this.aborted)
         {
             throw Fx.Exception.AsError(this.CreateObjectAbortedException());
         }
         if (this.count < this.maxCount)
         {
             this.count++;
             return true;
         }
         item = new AsyncWaitHandle();
         this.Waiters.Enqueue(item);
     }
     return item.WaitAsync(EnteredAsyncCallback, new EnterAsyncData(this, item, callback, state), timeout);
 }
コード例 #10
0
        private bool RemoveWaiter(AsyncWaitHandle waiter)
        {
            bool flag = false;

            lock (this.ThisLock)
            {
                for (int i = this.Waiters.Count; i > 0; i--)
                {
                    AsyncWaitHandle asyncWaitHandle = this.Waiters.Dequeue();
                    if (!object.ReferenceEquals(asyncWaitHandle, waiter))
                    {
                        this.Waiters.Enqueue(asyncWaitHandle);
                    }
                    else
                    {
                    }
                }
            }
            return(flag);
        }
コード例 #11
0
        public bool EnterAsync(TimeSpan timeout, FastAsyncCallback callback, object state)
        {
            AsyncWaitHandle item = null;

            lock (this.ThisLock)
            {
                if (this.aborted)
                {
                    throw Fx.Exception.AsError(this.CreateObjectAbortedException());
                }
                if (this.count < this.maxCount)
                {
                    this.count++;
                    return(true);
                }
                item = new AsyncWaitHandle();
                this.Waiters.Enqueue(item);
            }
            return(item.WaitAsync(EnteredAsyncCallback, new EnterAsyncData(this, item, callback, state), timeout));
        }
コード例 #12
0
        private AsyncWaitHandle EnterCore()
        {
            AsyncWaitHandle handle;

            lock (this.ThisLock)
            {
                if (this.aborted)
                {
                    throw Fx.Exception.AsError(this.CreateObjectAbortedException());
                }
                if (this.count < this.maxCount)
                {
                    this.count++;
                    return(null);
                }
                handle = new AsyncWaitHandle();
                this.Waiters.Enqueue(handle);
            }
            return(handle);
        }
コード例 #13
0
        public bool TryEnter(TimeSpan timeout)
        {
            AsyncWaitHandle waiter = this.EnterCore();

            if (waiter == null)
            {
                return(true);
            }
            bool flag = !waiter.Wait(timeout);

            if (this.aborted)
            {
                throw Fx.Exception.AsError(this.CreateObjectAbortedException());
            }
            if (flag && !this.RemoveWaiter(waiter))
            {
                flag = false;
            }
            return(!flag);
        }
コード例 #14
0
        private static void OnTimerComplete(object state)
        {
            AsyncWaiter     item   = (AsyncWaiter)state;
            AsyncWaitHandle parent = item.Parent;
            bool            flag   = false;

            lock (parent.syncObject)
            {
                if ((parent.asyncWaiters != null) && parent.asyncWaiters.Remove(item))
                {
                    item.TimedOut = true;
                    flag          = true;
                }
            }
            item.CancelTimer();
            if (flag)
            {
                item.Call();
            }
        }
コード例 #15
0
        // Abort the ThreadNeutralSemaphore object.
        public void Abort()
        {
            lock (this.ThisLock)
            {
                if (this.aborted)
                {
                    return;
                }

                this.aborted = true;

                if (this.waiters != null)
                {
                    while (this.waiters.Count > 0)
                    {
                        AsyncWaitHandle waiter = this.waiters.Dequeue();
                        waiter.Set();
                    }
                }
            }
        }
コード例 #16
0
        // remove a waiter from our queue. Returns true if successful. Used to implement timeouts.
        bool RemoveWaiter(AsyncWaitHandle waiter)
        {
            bool removed = false;

            lock (this.ThisLock)
            {
                for (int i = this.Waiters.Count; i > 0; i--)
                {
                    AsyncWaitHandle temp = this.Waiters.Dequeue();
                    if (object.ReferenceEquals(temp, waiter))
                    {
                        removed = true;
                    }
                    else
                    {
                        this.Waiters.Enqueue(temp);
                    }
                }
            }

            return(removed);
        }
コード例 #17
0
        public int Exit()
        {
            int num;
            int num1 = -1;

            lock (this.ThisLock)
            {
                if (!this.aborted)
                {
                    if (this.count != 0)
                    {
                        if (this.waiters == null || this.waiters.Count == 0)
                        {
                            ThreadNeutralSemaphore threadNeutralSemaphore = this;
                            threadNeutralSemaphore.count = threadNeutralSemaphore.count - 1;
                            num = this.count;
                        }
                        else
                        {
                            AsyncWaitHandle asyncWaitHandle = this.waiters.Dequeue();
                            num1 = this.count;
                            asyncWaitHandle.Set();
                            return(num1);
                        }
                    }
                    else
                    {
                        string invalidSemaphoreExit = InternalSR.InvalidSemaphoreExit;
                        throw Fx.Exception.AsError(new SynchronizationLockException(invalidSemaphoreExit));
                    }
                }
                else
                {
                    num = num1;
                }
            }
            return(num);
        }
コード例 #18
0
        static void OnTimerComplete(object state)
        {
            AsyncWaiter     waiter     = (AsyncWaiter)state;
            AsyncWaitHandle thisPtr    = waiter.Parent;
            bool            callWaiter = false;

            lock (thisPtr.syncObject)
            {
                // If still in the waiting list (that means it hasn't been signaled)
                if (thisPtr.asyncWaiters != null && thisPtr.asyncWaiters.Remove(waiter))
                {
                    waiter.TimedOut = true;
                    callWaiter      = true;
                }
            }

            waiter.CancelTimer();

            if (callWaiter)
            {
                waiter.Call();
            }
        }
コード例 #19
0
        AsyncWaitHandle SetupIdleWaiter(ref bool ownsLock)
        {
            AsyncWaitHandle idleEvent = new AsyncWaitHandle(EventResetMode.ManualReset);

            lock (this.activeOperationsLock)
            {
                if (this.idleWaiters == null)
                {
                    this.idleWaiters = new List<AsyncWaitHandle>();
                }

                this.idleWaiters.Add(idleEvent);
            }

            ReleaseLock(ref ownsLock);

            return idleEvent;
        }
 private AsyncWaitHandle EnterCore(ref object token, ref bool ownsLock)
 {
     AsyncWaitHandle item = null;
     lock (this.ThisLock)
     {
         if (this.owned)
         {
             if (token == null)
             {
                 item = new AsyncWaitHandle();
                 this.Waiters.Add(item);
                 return item;
             }
             return (AsyncWaitHandle) token;
         }
         try
         {
         }
         finally
         {
             this.owned = true;
             ownsLock = true;
         }
     }
     return item;
 }
 public BindReclaimedLockAsyncResult(InstancePersistenceContext context, AsyncWaitHandle wait, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.context = context;
     if (wait.WaitAsync(waitComplete, this, timeout))
     {
         this.context.ConcludeBindReclaimedLockHelper();
         base.Complete(true);
     }
 }
コード例 #22
0
        public bool EnterAsync(TimeSpan timeout, FastAsyncCallback callback, object state)
        {
            Fx.Assert(callback != null, "must have a non-null call back for async purposes");

            AsyncWaitHandle waiter = null;

            lock (this.ThisLock)
            {
                if (this.aborted)
                {
                    throw Fx.Exception.AsError(CreateObjectAbortedException());
                }

                if (this.count < this.maxCount)
                {
                    this.count++;
                    return true;
                }

                waiter = new AsyncWaitHandle();
                this.Waiters.Enqueue(waiter);
            }

            return waiter.WaitAsync(EnteredAsyncCallback, new EnterAsyncData(this, waiter, callback, state), timeout);
        }
 internal BindReclaimedLockException(AsyncWaitHandle markerWaitHandle) : base(SRCore.BindReclaimedLockException)
 {
     this.MarkerWaitHandle = markerWaitHandle;
 }
コード例 #24
0
        BookmarkResumptionResult ResumeProtocolBookmarkCore(Bookmark bookmark, object value, BookmarkScope bookmarkScope, bool bufferedReceiveEnabled, ref AsyncWaitHandle waitHandle, ref bool ownsLock)
        {
            Fx.Assert(this.state == State.Active, "WorkflowServiceInstance.State should be State.Active at this point.");

            BookmarkResumptionResult result;
            if (bookmarkScope == null)
            {
                result = this.Controller.ScheduleBookmarkResumption(bookmark, value);
            }
            else
            {
                result = this.Controller.ScheduleBookmarkResumption(bookmark, value, bookmarkScope);
            }

            if (result == BookmarkResumptionResult.NotReady && !bufferedReceiveEnabled)
            {
                if (waitHandle == null)
                {
                    waitHandle = new AsyncWaitHandle();
                }
                else
                {
                    waitHandle.Reset();
                }

                // Creation doesn't require the lock since it is guarded
                // by the executor lock.
                if (this.nextIdleWaiters == null)
                {
                    this.nextIdleWaiters = new List<AsyncWaitHandle>();
                }

                lock (this.activeOperationsLock)
                {
                    this.nextIdleWaiters.Add(waitHandle);
                }

                // We release the lock here so that the workflow will continue to process
                // until the NextIdle waiters get notified
                ReleaseLock(ref ownsLock);
            }

            return result;
        }
 private bool CleanupIdleWaiter(AsyncWaitHandle idleEvent, Exception waitException, ref bool ownsLock)
 {
     lock (this.activeOperationsLock)
     {
         if (!this.idleWaiters.Remove(idleEvent) && (waitException is TimeoutException))
         {
             ownsLock = true;
             return false;
         }
     }
     return true;
 }
コード例 #26
0
		public bool EnterAsync(TimeSpan timeout, FastAsyncCallback callback, object state)
		{
			bool flag;
			lock (this.ThisLock)
			{
				if (!this.aborted)
				{
					if (this.count >= this.maxCount)
					{
						AsyncWaitHandle asyncWaitHandle = new AsyncWaitHandle();
						this.Waiters.Enqueue(asyncWaitHandle);
						return asyncWaitHandle.WaitAsync(ThreadNeutralSemaphore.EnteredAsyncCallback, new ThreadNeutralSemaphore.EnterAsyncData(this, asyncWaitHandle, callback, state), timeout);
					}
					else
					{
						ThreadNeutralSemaphore threadNeutralSemaphore = this;
						threadNeutralSemaphore.count = threadNeutralSemaphore.count + 1;
						flag = true;
					}
				}
				else
				{
					throw Fx.Exception.AsError(this.CreateObjectAbortedException());
				}
			}
			return flag;
		}
コード例 #27
0
            // The token returned here must be fed to all Enter calls
            // and finally to CleanupWaiter by the thread that calls
            // SetupWaiter.  If the enter goes async (such as EnterAsync
            // might) then the caller should NOT call cleanup in the async
            // callback.
            public void SetupWaiter(bool isAbortPriority, ref object token)
            {
                lock (ThisLock)
                {
                    try
                    {
                    }
                    finally
                    {
                        token = new AsyncWaitHandle();

                        if (isAbortPriority)
                        {
                            this.Waiters.Insert(0, token);
                        }
                        else
                        {
                            this.Waiters.Add(token);
                        }
                    }
                }
            }
コード例 #28
0
            bool CheckState(ref bool ownsLock)
            {
                if (this.instance.state == State.Active && !this.instance.isRunnable)
                {
                    this.instance.RunCore();
                }

                // If instance state is non-Active, the AcquireOnIdle will succeed (WSI is doing nothing),
                // the caller is responsible for dealing with state vs. operation.
                // For instance, ResumeBookmark will call ValidateStateForResumeProtocolBookmark.
                if (this.instance.state == State.Active && this.instance.Controller.State == WorkflowInstanceState.Runnable)
                {
                    this.idleEvent = this.instance.SetupIdleWaiter(ref ownsLock);

                    try
                    {
                        if (this.idleEvent.WaitAsync(idleReceivedCallback, this, this.timeoutHelper.RemainingTime()))
                        {
                            ownsLock = true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }

                        if (this.instance.CleanupIdleWaiter(this.idleEvent, e, ref ownsLock))
                        {
                            throw;
                        }
                    }
                }

                return true;
            }
コード例 #29
0
		private AsyncWaitHandle EnterCore()
		{
			AsyncWaitHandle asyncWaitHandle;
			lock (this.ThisLock)
			{
				if (!this.aborted)
				{
					if (this.count >= this.maxCount)
					{
						AsyncWaitHandle asyncWaitHandle1 = new AsyncWaitHandle();
						this.Waiters.Enqueue(asyncWaitHandle1);
						return asyncWaitHandle1;
					}
					else
					{
						ThreadNeutralSemaphore threadNeutralSemaphore = this;
						threadNeutralSemaphore.count = threadNeutralSemaphore.count + 1;
						asyncWaitHandle = null;
					}
				}
				else
				{
					throw Fx.Exception.AsError(this.CreateObjectAbortedException());
				}
			}
			return asyncWaitHandle;
		}
 private bool WaitForCanPersist()
 {
     if (this.instance.Controller.IsPersistable)
     {
         return true;
     }
     this.instance.Controller.PauseWhenPersistable();
     this.mustWait = false;
     if (this.instance.IsIdle)
     {
         if (this.checkCanPersistEvent == null)
         {
             this.checkCanPersistEvent = new AsyncWaitHandle(EventResetMode.AutoReset);
         }
         this.instance.AddCheckCanPersistWaiter(this);
         this.mustWait = true;
     }
     this.instance.ReleaseLock(ref this.ownsLock);
     if (!this.mustWait)
     {
         return this.HandleWaitEvent();
     }
     if (onWaitEvent == null)
     {
         onWaitEvent = new Action<object, TimeoutException>(WorkflowServiceInstance.WaitForCanPersistAsyncResult.OnWaitEvent);
     }
     return (this.checkCanPersistEvent.WaitAsync(onWaitEvent, this, this.timeoutHelper.RemainingTime()) && this.HandleWaitEvent());
 }
コード例 #31
0
 public AsyncWaiter(AsyncWaitHandle parent, Action<object, TimeoutException> callback, object state)
 {
     this.Parent = parent;
     this.callback = callback;
     this.state = state;
 }
コード例 #32
0
 public AsyncWaiter(AsyncWaitHandle parent, Action <object, TimeoutException> callback, object state)
 {
     this.Parent   = parent;
     this.callback = callback;
     this.state    = state;
 }
 private bool RemoveWaiter(AsyncWaitHandle waiter)
 {
     bool flag = false;
     lock (this.ThisLock)
     {
         for (int i = this.Waiters.Count; i > 0; i--)
         {
             AsyncWaitHandle objA = this.Waiters.Dequeue();
             if (object.ReferenceEquals(objA, waiter))
             {
                 flag = true;
             }
             else
             {
                 this.Waiters.Enqueue(objA);
             }
         }
     }
     return flag;
 }
 public void EnsureAsyncWaitHandle()
 {
     this.receivedReplyEvent = new AsyncWaitHandle();
 }
コード例 #35
0
 internal LockResolutionMarker(InstanceHandle instanceHandle, long instanceVersion) : base(instanceHandle)
 {
     this.waitHandle = new AsyncWaitHandle(EventResetMode.ManualReset);
     this.InstanceVersion = instanceVersion;
 }
コード例 #36
0
            public PendingOperationAsyncResult(bool isFirstRequest, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.isFirstRequest = isFirstRequest;
                this.timeout = timeout;

                if (!this.isFirstRequest)
                {
                    this.waitHandle = new AsyncWaitHandle(EventResetMode.ManualReset);
                }
            }
 public void SetInteriorTransaction(Transaction interiorTransaction, bool needsCommit)
 {
     if (this.waitForTransaction != null)
     {
         throw Fx.Exception.AsError(new InvalidOperationException(SRCore.ExecuteMustBeNested));
     }
     bool flag = false;
     try
     {
         this.waitForTransaction = new AsyncWaitHandle(EventResetMode.ManualReset);
         interiorTransaction.EnlistVolatile((ISinglePhaseNotification) this, EnlistmentOptions.None);
         flag = true;
     }
     finally
     {
         if (!flag)
         {
             if (this.waitForTransaction != null)
             {
                 this.waitForTransaction.Set();
             }
         }
         else if (needsCommit)
         {
             this.transactionToCommit = (CommittableTransaction) interiorTransaction;
         }
     }
 }
コード例 #38
0
            bool WaitForCanPersist()
            {
                if (this.instance.Controller.IsPersistable)
                {
                    return true;
                }

                this.instance.Controller.PauseWhenPersistable();

                this.mustWait = false;
                if (this.instance.IsIdle)
                {
                    if (this.checkCanPersistEvent == null)
                    {
                        this.checkCanPersistEvent = new AsyncWaitHandle(EventResetMode.AutoReset);
                    }

                    // Will be signaled when WF is paused.
                    this.instance.AddCheckCanPersistWaiter(this);
                    this.mustWait = true;
                }

                this.instance.ReleaseLock(ref this.ownsLock);

                if (this.mustWait)
                {
                    if (onWaitEvent == null)
                    {
                        onWaitEvent = new Action<object, TimeoutException>(OnWaitEvent);
                    }

                    if (this.checkCanPersistEvent.WaitAsync(onWaitEvent, this, this.timeoutHelper.RemainingTime()))
                    {
                        return HandleWaitEvent();
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return HandleWaitEvent();
                }
            }
コード例 #39
0
        AsyncWaitHandle LoadInProgressWaitHandle(InstanceKey key)
        {
            AsyncWaitHandle waitHandle = null;

            if (key != null)
            {
                lock (ThisLock)
                {
                    this.loadsInProgress.TryGetValue(key, out waitHandle);
                    if (waitHandle == null)
                    {
                        AsyncWaitHandle newWaitHandle = new AsyncWaitHandle(EventResetMode.ManualReset);
                        this.loadsInProgress.Add(key, newWaitHandle);
                    }
                }
            }

            return waitHandle;
        }
コード例 #40
0
            AsyncWaitHandle EnterCore(ref object token, ref bool ownsLock)
            {
                AsyncWaitHandle waiter = null;

                lock (ThisLock)
                {
                    if (this.owned)
                    {
                        if (token == null)
                        {
                            waiter = new AsyncWaitHandle();
                            this.Waiters.Add(waiter);
                        }
                        else
                        {
                            waiter = (AsyncWaitHandle)token;
                        }
                    }
                    else
                    {
                        try
                        {
                        }
                        finally
                        {
                            this.owned = true;
                            ownsLock = true;
                        }
                    }
                }

                return waiter;
            }
 internal WorkflowHostingResponseContext()
 {
     this.responseWaitHandle = new AsyncWaitHandle(EventResetMode.AutoReset);
 }
コード例 #42
0
        bool CleanupIdleWaiter(AsyncWaitHandle idleEvent, Exception waitException, ref bool ownsLock)
        {
            lock (this.activeOperationsLock)
            {
                if (!this.idleWaiters.Remove(idleEvent))
                {
                    // If it wasn't in the list that means we ----d between throwing from Wait
                    // and setting the event.  This thread now is responsible for the lock.
                    if (waitException is TimeoutException)
                    {
                        // In the case of Timeout we let setting the event win and signal to
                        // ---- the exception

                        ownsLock = true;
                        return false;
                    }
                }
            }

            return true;
        }
 private void InitializePersistenceProviderDirectory()
 {
     bool flag;
     WorkflowServiceBehavior behavior = this.Host.Description.Behaviors.Find<WorkflowServiceBehavior>();
     int defaultMaxConcurrentInstances = ServiceThrottlingBehavior.DefaultMaxConcurrentInstances;
     ServiceThrottlingBehavior behavior2 = this.Host.Description.Behaviors.Find<ServiceThrottlingBehavior>();
     if (behavior2 != null)
     {
         defaultMaxConcurrentInstances = behavior2.MaxConcurrentInstances;
     }
     if (this.InstanceStore != null)
     {
         this.PersistenceProviderDirectory = new System.ServiceModel.Activities.Dispatcher.PersistenceProviderDirectory(this.InstanceStore, this.owner, this.instanceMetadataChanges, behavior.Activity, this.Host, DurableConsistencyScope.Global, defaultMaxConcurrentInstances);
     }
     else
     {
         this.PersistenceProviderDirectory = new System.ServiceModel.Activities.Dispatcher.PersistenceProviderDirectory(behavior.Activity, this.Host, defaultMaxConcurrentInstances);
     }
     lock (this.thisLock)
     {
         flag = this.state == 3;
     }
     if (flag)
     {
         if (this.handle != null)
         {
             this.handle.Free();
         }
         this.PersistenceProviderDirectory.Abort();
     }
     if ((this.InstanceStore != null) && !flag)
     {
         this.waitForStoreEventsLoop = new AsyncWaitHandle(EventResetMode.ManualReset);
         this.BeginWaitAndHandleStoreEvents(waitAndHandleStoreEventsCallback, this);
     }
 }
コード例 #44
0
        void InitializePersistenceProviderDirectory()
        {   
            int maxInstances = ServiceThrottlingBehavior.DefaultMaxConcurrentInstances;
            ServiceThrottlingBehavior serviceThrottlingBehavior = Host.Description.Behaviors.Find<ServiceThrottlingBehavior>();
            if (serviceThrottlingBehavior != null)
            {
                maxInstances = serviceThrottlingBehavior.MaxConcurrentInstances;
            }

            if (InstanceStore != null)
            {
                PersistenceProviderDirectory = new PersistenceProviderDirectory(InstanceStore, this.owner, this.instanceMetadataChanges, this.workflowDefinitionProvider, Host, DurableConsistencyScope.Global, maxInstances);
            }
            else
            {
                PersistenceProviderDirectory = new PersistenceProviderDirectory(this.workflowDefinitionProvider, Host, maxInstances);
            }

            bool aborted;
            lock (this.thisLock)
            {
                aborted = this.state == States.Aborted;
            }

            if (aborted)
            {
                if (this.handle != null)
                {
                    this.handle.Free();
                }

                PersistenceProviderDirectory.Abort();
            }

            // Start listening to store event
            if (InstanceStore != null && !aborted)
            {
                this.waitForStoreEventsLoop = new AsyncWaitHandle(EventResetMode.ManualReset);
                BeginWaitAndHandleStoreEvents(waitAndHandleStoreEventsCallback, this);
            }
        }
コード例 #45
0
        // remove a waiter from our queue. Returns true if successful. Used to implement timeouts.
        bool RemoveWaiter(AsyncWaitHandle waiter)
        {
            bool removed = false;

            lock (this.ThisLock)
            {
                for (int i = this.Waiters.Count; i > 0; i--)
                {
                    AsyncWaitHandle temp = this.Waiters.Dequeue();
                    if (object.ReferenceEquals(temp, waiter))
                    {
                        removed = true;
                    }
                    else
                    {
                        this.Waiters.Enqueue(temp);
                    }
                }
            }

            return removed;
        }
 public EnterAsyncData(ThreadNeutralSemaphore semaphore, AsyncWaitHandle waiter, FastAsyncCallback callback, object state)
 {
     this.Waiter = waiter;
     this.Semaphore = semaphore;
     this.Callback = callback;
     this.State = state;
 }
コード例 #47
0
        AsyncWaitHandle EnterCore()
        {
            AsyncWaitHandle waiter;

            lock (this.ThisLock)
            {
                if (this.aborted)
                {
                    throw Fx.Exception.AsError(CreateObjectAbortedException());
                }

                if (this.count < this.maxCount)
                {
                    this.count++;
                    return null;
                }

                waiter = new AsyncWaitHandle();
                this.Waiters.Enqueue(waiter);
            }

            return waiter;
        }
 private AsyncWaitHandle EnterCore()
 {
     AsyncWaitHandle handle;
     lock (this.ThisLock)
     {
         if (this.aborted)
         {
             throw Fx.Exception.AsError(this.CreateObjectAbortedException());
         }
         if (this.count < this.maxCount)
         {
             this.count++;
             return null;
         }
         handle = new AsyncWaitHandle();
         this.Waiters.Enqueue(handle);
     }
     return handle;
 }
コード例 #49
0
        public bool Wait(TimeSpan timeout)
        {
            bool flag;

            if (!this.isSignaled || this.isSignaled && this.resetMode == EventResetMode.AutoReset)
            {
                lock (this.syncObject)
                {
                    if (!this.isSignaled || this.resetMode != EventResetMode.AutoReset)
                    {
                        if (!this.isSignaled)
                        {
                            bool flag1 = false;
                            try
                            {
                                try
                                {
                                }
                                finally
                                {
                                    AsyncWaitHandle asyncWaitHandle = this;
                                    asyncWaitHandle.syncWaiterCount = asyncWaitHandle.syncWaiterCount + 1;
                                    flag1 = true;
                                }
                                if (timeout != TimeSpan.MaxValue)
                                {
                                    if (!Monitor.Wait(this.syncObject, timeout))
                                    {
                                        flag = false;
                                        return(flag);
                                    }
                                }
                                else
                                {
                                    if (!Monitor.Wait(this.syncObject, -1))
                                    {
                                        flag = false;
                                        return(flag);
                                    }
                                }
                            }
                            finally
                            {
                                if (flag1)
                                {
                                    AsyncWaitHandle asyncWaitHandle1 = this;
                                    asyncWaitHandle1.syncWaiterCount = asyncWaitHandle1.syncWaiterCount - 1;
                                }
                            }
                        }
                    }
                    else
                    {
                        this.isSignaled = false;
                    }
                    return(true);
                }
                return(flag);
            }
            return(true);
        }