/// <summary>
        /// Attempts to execute the given function for the pip after acquiring the resources to run the pip and
        /// provides cancellation when resources are limited
        /// </summary>
        public async Task <T> ExecuteWithResourcesAsync <T>(
            OperationContext operationContext,
            Process processPip,
            ProcessMemoryCounters expectedMemoryCounters,
            bool allowCancellation,
            ManagedResourceExecute <T> execute)
        {
            ResourceScope scope;

            using (operationContext.StartOperation(PipExecutorCounter.AcquireResourcesDuration))
            {
                scope = AcquireResourceScope(processPip, expectedMemoryCounters, allowCancellation);
            }

            using (scope)
            {
                var result = await execute(scope);

                scope.Complete();
                return(result);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Attempts to execute the given function for the pip after acquiring the resources to run the pip and
        /// provides cancellation when resources are limited
        /// </summary>
        public async Task <T> ExecuteWithResources <T>(
            OperationContext operationContext,
            PipId pipId,
            ProcessMemoryCounters expectedMemoryCounters,
            bool allowCancellation,
            ManagedResourceExecute <T> execute)
        {
            ResourceScope scope;

            using (operationContext.StartOperation(PipExecutorCounter.AcquireResourcesDuration))
            {
                scope = AcquireResourceScope(pipId, expectedMemoryCounters, allowCancellation);
            }

            using (scope)
            {
                var result = await execute(scope.Token, registerQueryRamUsageMb : scope.RegisterQueryRamUsageMb);

                scope.Complete();
                return(result);
            }
        }