diff --git a/src/ResourceManager/Compute/Commands.Compute/Strategies/AsyncCmdletExtensions.cs b/src/ResourceManager/Compute/Commands.Compute/Strategies/AsyncCmdletExtensions.cs index b256bbd46bf0..b9c8b1bab932 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Strategies/AsyncCmdletExtensions.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Strategies/AsyncCmdletExtensions.cs @@ -16,7 +16,6 @@ using System; using System.Collections.Generic; using System.Management.Automation; -using System.Threading; using System.Threading.Tasks; namespace Microsoft.Azure.Commands.Compute.Strategies @@ -32,6 +31,8 @@ public static void StartAndWait( this Cmdlet cmdlet, Func createAndStartTask) { var asyncCmdlet = new AsyncCmdlet(cmdlet); + string previousX = null; + string previousOperation = null; asyncCmdlet.Scheduler.Wait( createAndStartTask(asyncCmdlet), () => @@ -52,17 +53,25 @@ public static void StartAndWait( var percent = (int)(progress * 100.0); var r = new[] { "|", "/", "-", "\\" }; var x = r[DateTime.Now.Second % 4]; - cmdlet.WriteProgress( - new ProgressRecord( - 0, - "Creating Azure resources", - percent + "% " + x) - { - CurrentOperation = activeTasks.Count > 0 - ? "Creating " + string.Join(", ", activeTasks) + "." - : null, - PercentComplete = percent, - }); + var operation = activeTasks.Count > 0 + ? "Creating " + string.Join(", ", activeTasks) + "." + : null; + + // write progress only if it's changed. + if (x != previousX || operation != previousOperation) + { + cmdlet.WriteProgress( + new ProgressRecord( + 0, + "Creating Azure resources", + percent + "% " + x) + { + CurrentOperation = operation, + PercentComplete = percent, + }); + previousX = x; + previousOperation = operation; + } } }); }