Код: Выделить всё
int retries = 3;
while(true) {
try {
DoSomething();
break; // success!
} catch {
if(--retries == 0) throw;
else Thread.Sleep(1000);
}
}
Код: Выделить всё
TryThreeTimes(DoSomething);
Подробнее здесь: https://stackoverflow.com/questions/156 ... etry-logic
Мобильная версия