Exemple #1
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;
                        }
                    }
                }
            }
        }
Exemple #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);
        }
Exemple #3
0
        public async Task <bool> Reserve()
        {
            synchronizationContext = await synchronizationHandle.GetFreeInstanceAsync();

            return(synchronizationContext.IsSuccess);
        }