提交 aefa753e 编写于 作者: S Sam Harwell

Updates from code review feedback

上级 1d5c75e3
......@@ -13,7 +13,18 @@ namespace Microsoft.VisualStudio.IntegrationTest.Utilities
public static class AutomationElementExtensions
{
private const int UIA_E_ELEMENTNOTAVAILABLE = unchecked((int)0x80040201);
private const int AutomationRetryCount = 3;
/// <summary>
/// The number of times to retry a UI automation operation that failed with
/// <see cref="UIA_E_ELEMENTNOTAVAILABLE"/>, not counting the initial call. A value of 2 means the operation
/// will be attempted a total of three times.
/// </summary>
private const int AutomationRetryCount = 2;
/// <summary>
/// The delay between retrying a UI automation operation that failed with
/// <see cref="UIA_E_ELEMENTNOTAVAILABLE"/>.
/// </summary>
private static readonly TimeSpan AutomationRetryDelay = TimeSpan.FromMilliseconds(100);
/// <summary>
......@@ -334,6 +345,7 @@ private static string GetNameForExceptionMessage(this IUIAutomationElement eleme
private static void RetryIfNotAvailable<T>(Action<T> action, T state)
{
// NOTE: The loop termination condition if exceptions are thrown is in the exception filter
for (var i = 0; true; i++)
{
try
......@@ -341,7 +353,7 @@ private static void RetryIfNotAvailable<T>(Action<T> action, T state)
action(state);
return;
}
catch (COMException e) when (e.HResult == UIA_E_ELEMENTNOTAVAILABLE && i < AutomationRetryCount - 1)
catch (COMException e) when (e.HResult == UIA_E_ELEMENTNOTAVAILABLE && i < AutomationRetryCount)
{
Thread.Sleep(AutomationRetryDelay);
continue;
......@@ -351,13 +363,14 @@ private static void RetryIfNotAvailable<T>(Action<T> action, T state)
private static TResult RetryIfNotAvailable<T, TResult>(Func<T, TResult> function, T state)
{
// NOTE: The loop termination condition if exceptions are thrown is in the exception filter
for (var i = 0; true; i++)
{
try
{
return function(state);
}
catch (COMException e) when (e.HResult == UIA_E_ELEMENTNOTAVAILABLE && i < AutomationRetryCount - 1)
catch (COMException e) when (e.HResult == UIA_E_ELEMENTNOTAVAILABLE && i < AutomationRetryCount)
{
Thread.Sleep(AutomationRetryDelay);
continue;
......
......@@ -288,7 +288,7 @@ public string[] GetLightBulbActions()
var view = GetActiveTextView();
var broker = GetComponentModel().GetService<ILightBulbBroker>();
return (await GetLightBulbActionsAsync(broker, view)).Select(a => a.DisplayText).ToArray();
return (await GetLightBulbActionsAsync(broker, view).ConfigureAwait(false)).Select(a => a.DisplayText).ToArray();
});
}
......@@ -312,7 +312,7 @@ private async Task<IEnumerable<ISuggestedAction>> GetLightBulbActionsAsync(ILigh
actionSets = Array.Empty<SuggestedActionSet>();
}
return await SelectActionsAsync(actionSets);
return await SelectActionsAsync(actionSets).ConfigureAwait(false);
}
public void ApplyLightBulbAction(string actionName, FixAllScope? fixAllScope, bool blockUntilComplete)
......@@ -323,7 +323,7 @@ public void ApplyLightBulbAction(string actionName, FixAllScope? fixAllScope, bo
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var activeTextView = GetActiveTextView();
await lightBulbAction(activeTextView);
await lightBulbAction(activeTextView).ConfigureAwait(false);
});
if (blockUntilComplete)
......@@ -400,7 +400,7 @@ private async Task<IEnumerable<ISuggestedAction>> SelectActionsAsync(IEnumerable
foreach (var action in actionSet.Actions)
{
actions.Add(action);
actions.AddRange(await SelectActionsAsync(await action.GetActionSetsAsync(CancellationToken.None)));
actions.AddRange(await SelectActionsAsync(await action.GetActionSetsAsync(CancellationToken.None).ConfigureAwait(false)).ConfigureAwait(false));
}
}
}
......@@ -426,8 +426,8 @@ private static async Task<FixAllSuggestedAction> GetFixAllSuggestedActionAsync(I
if (action.HasActionSets)
{
var nestedActionSets = await action.GetActionSetsAsync(CancellationToken.None);
fixAllSuggestedAction = await GetFixAllSuggestedActionAsync(nestedActionSets, fixAllScope);
var nestedActionSets = await action.GetActionSetsAsync(CancellationToken.None).ConfigureAwait(false);
fixAllSuggestedAction = await GetFixAllSuggestedActionAsync(nestedActionSets, fixAllScope).ConfigureAwait(false);
if (fixAllSuggestedAction != null)
{
return fixAllSuggestedAction;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册