Sure. Just structure your code in such a way to support that. For example
if your oringal method looked like this:
void Foo()
{
<Do stuff>
Try {
<DoDB Stuff>
} catch {}
<Do More Stuff>
}
You could rewrite it like this:
void Foo()
{
<Do Stuff>
while (!DoDBStuff())
{
Thread.Sleep(1000);
}
<Do More Suff)
}
bool DoDBStuff()
{
try{
<DoDB Stuff>
return true;
} catch {
return false;
}
}
Note, you wouldn't want to do leave the while loop like that as it could
become an infinite loop. You'd most likely want to put some counter in
there to kick out of the loop after so many retries. You'd then need to
check to see if it ever succeeded and probably throw an exception instead
of "Doing more stuff" in the event that it never succeeded.
You also want to be careful with Thread.Sleep. It will let you pause
before resuming. However, if this is running in your main thread it will
freeze the applications UI as well.
--
Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com
Luke Davis said:
I'm new so bear with me. Is there a way for the catch to fix a problem
then start the try over again?
For example, I have this console application sync a remote database and
it takes hours. Sometimes the link, for no apparent reason will drop
and will trigger the catch. I want the catch to wait a minute then
start the try over again. Possible? or not?
Luke