コード例 #1
0
        public async Task <ResponseTimeInformation> ExecuteAllPendingLazyOperationsAsync(CancellationToken token = default(CancellationToken))
        {
            using (AsyncTaskHolder())
            {
                var requests = new List <GetRequest>();
                for (int i = 0; i < PendingLazyOperations.Count; i++)
                {
                    var req = PendingLazyOperations[i].CreateRequest(Context);
                    if (req == null)
                    {
                        PendingLazyOperations.RemoveAt(i);
                        i--; // so we'll recheck this index
                        continue;
                    }

                    requests.Add(req);
                }

                if (requests.Count == 0)
                {
                    return(new ResponseTimeInformation());
                }

                try
                {
                    var sw = Stopwatch.StartNew();

                    IncrementRequestCount();

                    var responseTimeDuration = new ResponseTimeInformation();

                    while (await ExecuteLazyOperationsSingleStep(responseTimeDuration, requests, sw, 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);
                        }
                    }

                    sw.Stop();
                    responseTimeDuration.TotalClientDuration = sw.Elapsed;
                    return(responseTimeDuration);
                }
                finally
                {
                    PendingLazyOperations.Clear();
                }
            }
        }
コード例 #2
0
        public ResponseTimeInformation ExecuteAllPendingLazyOperations()
        {
            var requests = new List <GetRequest>();

            for (int i = 0; i < PendingLazyOperations.Count; i++)
            {
                var req = PendingLazyOperations[i].CreateRequest(Context);
                if (req == null)
                {
                    PendingLazyOperations.RemoveAt(i);
                    i--; // so we'll recheck this index
                    continue;
                }
                requests.Add(req);
            }

            if (requests.Count == 0)
            {
                return(new ResponseTimeInformation());
            }

            try
            {
                var sw = Stopwatch.StartNew();

                IncrementRequestCount();

                var responseTimeDuration = new ResponseTimeInformation();

                while (ExecuteLazyOperationsSingleStep(responseTimeDuration, requests, sw))
                {
                    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();
            }
        }
コード例 #3
0
        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();
            }
        }
コード例 #4
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();
            }
        }