I constantly have some situations in which I have to retry some operations if they fail, giving up after certain number of times, and taking a short breaks between attempts.
Is there a way to create a ‘retry method’ that will enable me not to copy the code around every time I do that?
Got tired of copy/paste the same code over and over again, so I created a method that accepts the delegate of the task that has to be done. Here it is:
To use it, I would simply write:
In this example I am appending a file that gets locked with some external process, only way to write it is to retry it several times until the process is done with it…
I would sure love to see better ways of handling this particular pattern (retrying).
EDIT: I looked at Gallio in another answer, and it is really great. Look at this example:
It does everything. It will even watch your kids while you code 🙂 But, I strive for simplicity, and still am using .NET 2.0. So I guess that my example will still be of some use to you.