- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to write retry logic in C#?
Retry logic is implemented whenever there is a failing operation. Implement retry logic only where the full context of a failing operation.
It's important to log all connectivity failures that cause a retry so that underlying problems with the application, services, or resources can be identified.
Example
class Program{ public static void Main(){ HttpClient client = new HttpClient(); dynamic res = null; var retryAttempts = 3; var delay = TimeSpan.FromSeconds(2); RetryHelper.Retry(retryAttempts, delay, () =>{ res = client.GetAsync("https://example22.com/api/cycles/1"); }); Console.ReadLine(); } } public static class RetryHelper{ public static void Retry(int times, TimeSpan delay, Action operation){ var attempts = 0; do{ try{ attempts++; System.Console.WriteLine(attempts); operation(); break; } catch (Exception ex){ if (attempts == times) throw; Task.Delay(delay).Wait(); } } while (true); } }
- Related Articles
- Introduction to Mathematical Logic!\n
- Logic Gates in Python
- Negation logic in SAP ABAP
- How to write "Hello World" in C#?
- Implement divide & conquer logic in JavaScript to implement QuickSort
- Chip Select Logic in 8085 Microprocessor
- Arithmetic Logic Unit (ALU)
- What is Logic Gates?
- How to write a singleton class in C++?
- How to write a short literal in C++?
- How to write "Hello World" Program in C++?
- How to write the first program in C#?
- How to write multi-line comments in C#?
- How to write single-line comments in C#?
- How to write long strings in Multi-lines C/C++?

Advertisements