Beispiel #1
0
        public async Task WithRetry_InvokeAsync()
        {
            var ac = new WithRetryTestClass();
            WithRetry.SetDefaultOptions(new RetryOptions(3, TimeSpan.FromSeconds(15)));

            var fr2 = await WithRetry.InvokeAsync(async () => await ac.FunctionAsync(1));

            await Assert.ThrowsExceptionAsync<ExceededMaxAttemptsException>(async () => { var fr = await WithRetry.InvokeAsync(() => ac.ExceptionAsync(1)); });

            WithRetry.SetDefaultOptions(new RetryOptions(100000, TimeSpan.FromMilliseconds(10)));

            await Assert.ThrowsExceptionAsync<ExceededMaxWaitTimeException>(async () => { var fr = await WithRetry.InvokeAsync(() => ac.ExceptionAsync(1)); });
        }
Beispiel #2
0
        private Task F()
        {
            var ac = new WithRetryTestClass();

            try
            {
                var x = 1;
                var y = WithRetryTestClass.Invoke(() => { return(ac.FunctionAsync(x)); });
                WithRetryTestClass.Invoke(async() =>
                {
                    var b = await ac.FunctionAsync(x);
                    if (b == 2)
                    {
                        Console.Write("");
                    }
                });
                return(y);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(Task.FromException(ex));
            }
        }