public async Task <ResponseTimeInformation> ExecuteAllPendingLazyOperationsAsync(CancellationToken token = default(CancellationToken))
        {
            if (PendingLazyOperations.Count == 0)
            {
                return(new ResponseTimeInformation());
            }

            try
            {
                var sw = Stopwatch.StartNew();

                IncrementRequestCount();

                var responseTimeDuration = new ResponseTimeInformation();

                while (await ExecuteLazyOperationsSingleStep(responseTimeDuration).WithCancellation(token).ConfigureAwait(false))
                {
                    await TimeoutManager.WaitFor(TimeSpan.FromMilliseconds(100), token).ConfigureAwait(false);
                }

                responseTimeDuration.ComputeServerTotal();


                foreach (var pendingLazyOperation in PendingLazyOperations)
                {
                    Action <object> value;
                    if (OnEvaluateLazy.TryGetValue(pendingLazyOperation, out value))
                    {
                        value(pendingLazyOperation.Result);
                    }
                }
                responseTimeDuration.TotalClientDuration = sw.Elapsed;
                return(responseTimeDuration);
            }
            finally
            {
                PendingLazyOperations.Clear();
            }
        }
Esempio n. 2
0
        public ResponseTimeInformation ExecuteAllPendingLazyOperations()
        {
            if (PendingLazyOperations.Count == 0)
            {
                return(new ResponseTimeInformation());
            }

            try
            {
                var sw = Stopwatch.StartNew();

                IncrementRequestCount();

                var responseTimeDuration = new ResponseTimeInformation();

                while (ExecuteLazyOperationsSingleStep(responseTimeDuration))
                {
                    Thread.Sleep(100);
                }

                responseTimeDuration.ComputeServerTotal();


                foreach (var pendingLazyOperation in PendingLazyOperations)
                {
                    Action <object> value;
                    if (OnEvaluateLazy.TryGetValue(pendingLazyOperation, out value))
                    {
                        value(pendingLazyOperation.Result);
                    }
                }
                responseTimeDuration.TotalClientDuration = sw.Elapsed;
                return(responseTimeDuration);
            }
            finally
            {
                PendingLazyOperations.Clear();
            }
        }