Sunday, June 25, 2017

Simple retry mechanism in Delphi

Hi all,
I want to share with you a nice unit that provide a retry pattern. How many times you want to execute some code and, if that method throws an exception, you want to retry executing it several times? For example when you try to connect to a service or network resource or a database. The operation was something that failed frequently enough that it was necessary sometimes to retry until it succeeded. With this unit you enable an application to handle transient failures by transparently retrying a failed operation.
Here is the RetryHelperU:
The snippet is very simple to understand: you have to specify the number of retries, the milliseconds between each retry and a TProc that represents the operation to do.
I also added this project to my Delphi Demos repository.
I hope it will be useful!