Exemple #1
0
        /// <summary>
        /// Выполняет function до успешного завершения, либо истечения количества попыток
        /// </summary>
        /// <param name="function">функция для выполнения</param>
        /// <param name="attemptsCount">количество попыток</param>
        /// <param name="timeInterval">временной интервал</param>
        /// <returns></returns>
        public async static Task Execute(ExecuteParams executeParams)
        {
            bool needRepeat = false;
            try
            {
                await executeParams.RequestFunction(executeParams.Url, executeParams.Proxy, executeParams.Step);
                needRepeat = false;
            }
            catch (Exception ex)
            {
                executeParams.AttemptsCount--;
                if (executeParams.AttemptsCount > 0)
                    needRepeat = true;
                else
                    executeParams.ExceptionAction(executeParams.Url, executeParams.Proxy, executeParams.Step, ex);
            }

            if (needRepeat)
            {
                await Task.Delay(executeParams.TimeInterval);
                await Execute(executeParams);
            }
        }