int tryTimes = 0;
while (tryTimes < 2) // set retry times you want
{
try
{
// do something with your retry code
break; // if working properly, break here.
}
catch
{
// do nothing and just retry
}
finally
{
tryTimes++; // ensure whether exception or not, retry time++ here
}
}