示例#1
0
        private void KeepUpdatingSession()
        {
            while (true)
            {
                _uiHelper.Sleep(TimeBetweenUpdates);

                if (_stopFlag)
                {
                    return;
                }

                try
                {
                    ReloadSessions();
                }
                catch (ThreadAbortException)
                {
                    throw;
                }
                catch (ThreadInterruptedException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    _log.ErrorException("Exception while reloading session", e);
                }
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="ReturnType"></typeparam>
        /// <param name="action"></param>
        /// <param name="numberOfTries"></param>
        /// <param name="retryInterval"></param>
        /// <param name="catchAction"></param>
        /// <param name="throwExceptions"></param>
        /// <returns>Default if fails</returns>
        public static ReturnType RetryAction <ReturnType>(Func <ReturnType> action, int numberOfTries, TimeSpan retryInterval, Action catchAction = null, bool throwExceptions = true)
        {
            var tryAttemptsRemaining = numberOfTries;
            var accumulatingTimeSpan = retryInterval;

            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            do
            {
                try
                {
                    var result = action();
                    return(result);
                }
                catch (Exception e)
                {
                    Log.ErrorException("Failed to invoke action", e);

                    if (catchAction != null)
                    {
                        catchAction();
                    }

                    if (tryAttemptsRemaining <= 1 && throwExceptions)
                    {
                        throw;
                    }

                    UiHelper.Sleep(accumulatingTimeSpan);
                    accumulatingTimeSpan += retryInterval;
                }

                tryAttemptsRemaining--;
            } while (tryAttemptsRemaining > 0);

            return(default(ReturnType));
        }
        public virtual void MakeSureExecuteAction(Action action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            var methodName = _uiHelper.GetPrevLocation(2);

            _log.Debug("Executing " + methodName);

            RetryStartUntilReady();

            bool failed = true;

            while (failed)
            {
                try
                {
                    action.Invoke();
                    failed       = false;
                    _failedState = false;
                }
                catch (CommunicationException e)
                {
                    _failedState = true;
                    _log.Info(_connectionErrorStr + " while calling " + methodName + " error: " + e.Message);
                }

                if (failed)
                {
                    _uiHelper.Sleep(RestartIntervalMilliseconds);
                    TryToStart();
                }
            }
        }