Пример #1
0
 public void Free()
 {
     if (synchronizationContext != null)
     {
         synchronizationHandle.ReleaseInstance(synchronizationContext.Set(true));
     }
 }
Пример #2
0
        async void ProcessLoop()
        {
            var accessObj = await AccessObjGenerator.GetFreeInstanceAsync();

            if (!isOnHold)
            {
                if (TotalTaskCount > 0)
                {
                    if (currentExecCounter < taskThreshold)
                    {
                        tempCounter = taskThreshold - currentExecCounter;
                        iterateAndExecute(HighPriorityTasks, Math.Min(tempCounter, HighPriorityTasks.Count));

                        tempCounter = taskThreshold - currentExecCounter;
                        iterateAndExecute(MediumPriorityTasks, Math.Min(tempCounter, MediumPriorityTasks.Count));

                        tempCounter = taskThreshold - currentExecCounter;
                        iterateAndExecute(LowPriorityTasks, Math.Min(tempCounter, LowPriorityTasks.Count));
                    }
                    if (currentExecCounter <= 0)
                    {
                        tempCounter = taskThreshold - currentExecCounter;
                        iterateAndExecute(IdlePriorityTasks, Math.Min(tempCounter, IdlePriorityTasks.Count));
                    }
                }
            }

            AccessObjGenerator.ReleaseInstance(accessObj);
        }
Пример #3
0
        public async Task <T> ExecuteTaskAsync <T>(Func <Task <T> > TaskReference)
        {
            Guid newOperationId = Guid.NewGuid();

            lastOperationId = newOperationId;

            var accessObj = await throttler.GetFreeInstanceAsync();

            try
            {
                var response = await ExecuteTaskAsyncInternal <T>(TaskReference, newOperationId);

                return(response);
            }
            finally
            {
                throttler.ReleaseInstance(accessObj);
                if (!isInPauseState && throttler.GetQueueSize() == 0)
                {
                    if (lastOperationId == newOperationId)
                    {
                        await Task.Delay(initialDelayInMilliseconds);

                        if (lastOperationId == newOperationId)
                        {
                            isInPauseState = true;
                        }
                    }
                }
            }
        }
Пример #4
0
        public void ReleaseOperation(string operationKey, T operationResult)
        {
            InstanceQM <T> throttler = null;
            var            isSuccess = RedundantTaskThrottler.TryGetValue(operationKey, out throttler);

            if (isSuccess)
            {
                if (throttler != null)
                {
                    throttler.ReleaseInstance(operationResult);
                }
                RedundantTaskThrottler.TryRemove(operationKey, out throttler);
            }
        }