コード例 #1
0
        /// <summary>
        /// Schedules retrying on the given request.
        /// </summary>
        /// <param name="request">The request to retry later.</param>
        private void ScheduleRetry(CalqRequest request)
        {
            if (request.Retries < CalqApiDispatcher.MaxRetries)
            {
                lock (RetryQueue)
                {
                    request.NextRetry = DateTime.Now.AddSeconds(InitialRetryDelaySeconds * Math.Pow(1.5, request.Retries + 1));
                    RetryQueue.AddLast(request);
                }

                lock (CreationLock)
                {
                    if (CurrentRetryTask == null || CurrentRetryTask.IsCompleted)
                    {
                        CurrentRetryTask = Task.Factory.StartNew(() => { BackgroundRetryLoop(); });
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Enqueues the given API call to be dispatched. Will start background process to dispatch if not currently running.
        /// </summary>
        /// <param name="request"></param>
        internal void EnqueueApiCall(CalqRequest request)
        {
            CallQueue.Enqueue(request);

            lock (CreationLock)
            {
                if (CurrentDispatchTask == null || CurrentDispatchTask.IsCompleted)
                {
                    CurrentDispatchTask = Task.Factory.StartNew(() => { BackgroundDispatchLoop(); });
                }
            }
        }