What is the cause of the error?
If this is a resource problem, such as accessing something like a connection or object, then you may need to use monitors, semaphores, or just locking.
lock (resource) { Dosomething(resource); }
Thus, if the previous method accesses the resource, you can wait until it releases the resource to continue.
Ideally, you don't need to run a loop to execute something every time it fails. It does not work at all, you would like to know about the problem and fix it. Having a cycle to always keep trying is not the right way.
source share