示例#1
0
        static void Main()
        {
            // cant use await here coz Main methos cannot be async so used Wait() method instead
            RetryHandler.RetryForAsync <WebException>(async() =>
            {
                string content = await DownloadContentAsync();

                Console.Write(content);
            }, 60000, 500, httpRequestException => httpRequestException.Status == WebExceptionStatus.Timeout ||
                                                      httpRequestException.Status == WebExceptionStatus.ConnectFailure).Wait();

            // cant use await here coz Main methos cannot be async so used Wait() method instead
            RetryHandler.RetryAsync <WebException>(async() =>
            {
                string content = await DownloadContentAsync();

                Console.Write(content);
            }, 5, 500, httpRequestException => httpRequestException.Status == WebExceptionStatus.Timeout ||
                                                   httpRequestException.Status == WebExceptionStatus.ConnectFailure).Wait();


            RetryHandler.Retry <WebException>(() =>
            {
                string content = DownloadContent();

                Console.Write(content);
            }, 6, 500, httpRequestException => httpRequestException.Status == WebExceptionStatus.Timeout ||
                                              httpRequestException.Status == WebExceptionStatus.ConnectFailure, Logger);


            RetryHandler.RetryFor <WebException>(() =>
            {
                string content = DownloadContent();

                Console.Write(content);
            }, TimeSpan.FromSeconds(75), TimeSpan.FromSeconds(2), httpRequestException => httpRequestException.Status == WebExceptionStatus.Timeout ||
                                                 httpRequestException.Status == WebExceptionStatus.ConnectFailure, Logger);

            Console.Read();
        }