Occasionally I have a need to retry an operation several times before giving up. My code is like:
int retries = 3; while(true) { try { DoSomething();
public delegate void ThingToTryDeletage(); public static void TryNTimes(ThingToTryDelegate, int N, int sleepTime) { while(true) { try { ThingToTryDelegate(); } catch { if( --N == 0) throw; else Thread.Sleep(time); } }