tools/VsIdeHostAdapter/TargetAddIn/AgentSide/VsIdeHostAdapter.cs
/// <summary>
/// Invokes specified invoker inside a loop with try-catch/everything and retries until reaches timeout or until each of the following is true:
/// - The invoker does not throw exception.
/// - If the additional condition delegate is specified, it must return true.
/// </summary>
/// <param name="invoker">The method to invoke</param>
/// <param name="stopCondition">If specified, to break from the loop, it must be true. The condition delegate must not throw.</param>
/// <param name="timeout">Timeout to stop retries after.</param>
/// <returns>True on success, false on timeout.</returns>
Invokes specified invoker inside a loop with try-catch/everything and retries until reaches timeout or until each of the following is true:
The invoker does not throw exception.
If the additional condition delegate is specified, it must return true.
Invokes specified invoker inside a loop with try - catch / everything and retries until reaches timeout or until each of the following is true : The invoker does not throw exception . If the additional condition delegate is specified it must return true .
private bool InvokeWithRetry(MethodInvoker invoker, BoolMethodInvoker stopCondition, TimeSpan timeout)
        {
            Debug.Assert(invoker != null);
            Stopwatch timer = Stopwatch.StartNew();
            bool hasTimedOut = true;
            try
            {
                do
                {
                    bool isExceptionThrown = false;
                    try
                    {
                        invoker.Invoke();
                    }
                    catch
                    {
                        isExceptionThrown = true;
                    }
                    if (!isExceptionThrown &&
                        (stopCondition == null || stopCondition.Invoke()))
                    {
                        hasTimedOut = false;
                        break;
                    }
                    Thread.Sleep(RegistrySettings.BaseSleepDuration);   
                } while (timer.Elapsed < timeout);
            }
            finally
            {
                timer.Stop();
            }
            return !hasTimedOut;
        }
private bool InvokeWithRetry ( MethodInvoker invoker , BoolMethodInvoker stopCondition , TimeSpan timeout ) { Debug . Assert ( invoker != null ) ; Stopwatch timer = Stopwatch . StartNew ( ) ; bool hasTimedOut = true ; try { do { bool isExceptionThrown = false ; try { invoker . Invoke ( ) ; } catch { isExceptionThrown = true ; } if ( ! isExceptionThrown && ( stopCondition == null || stopCondition . Invoke ( ) ) ) { hasTimedOut = false ; break ; } Thread . Sleep ( RegistrySettings . BaseSleepDuration ) ; } while ( timer . Elapsed < timeout ) ; } finally { timer . Stop ( ) ; } return ! hasTimedOut ; }
Invokes specified invoker inside a loop with try-catch/everything and retries until reaches timeout or until each of the following is true:
 The invoker does not throw exception.
Invokes specified invoker inside a loop with try - catch / everything and retries until reaches timeout or until each of the following is true : The invoker does not throw exception .
// If there was no exception, also check for stop condition. // Note: condition.Invoke() must not throw. If it throws, we also throw from here. // This is to prevent 100% CPU consumption.
True on success, false on timeout.
True on success false on timeout .
invoker
MethodInvoker
The method to invoke
The method to invoke
stopCondition
BoolMethodInvoker
If specified, to break from the loop, it must be true. The condition delegate must not throw.
If specified to break from the loop it must be true . The condition delegate must not throw .
timeout
TimeSpan
Timeout to stop retries after.
Timeout to stop retries after .