mrlacey/WindowsTestHelpers

Add RetryOnException helper

Closed this issue · 1 comments

Accept the type of the exception to check for, and an (optional) max number of retries to attempt.

pseudocode

public static void Retry<T>(Action action, int maxRetryAttempts = 1)
{
    var attempts = 1;

    try
    {
        action.Invoke();
    }
    catch (Exception exc)
    {
        if (exc is T)
        {
            if (attempts <= maxRetryAttempts)
            {
                // retry - TODO: put this logic in a while loop
            }
            else
            {
                 rethrow;
            }
        }
    }
}

Be sure to add lots of testing :)

Added in v 0.4.0