Skip to content

Commit f746121

Browse files
authored
Merge pull request #5487 from sergey-shandar/sergey-progress-bar
Progress Bar update
2 parents 5c0bfb2 + 911d5f0 commit f746121

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/ResourceManager/Compute/Commands.Compute/Strategies/AsyncCmdletExtensions.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using System;
1717
using System.Collections.Generic;
1818
using System.Management.Automation;
19-
using System.Threading;
2019
using System.Threading.Tasks;
2120

2221
namespace Microsoft.Azure.Commands.Compute.Strategies
@@ -32,6 +31,8 @@ public static void StartAndWait(
3231
this Cmdlet cmdlet, Func<IAsyncCmdlet, Task> createAndStartTask)
3332
{
3433
var asyncCmdlet = new AsyncCmdlet(cmdlet);
34+
string previousX = null;
35+
string previousOperation = null;
3536
asyncCmdlet.Scheduler.Wait(
3637
createAndStartTask(asyncCmdlet),
3738
() =>
@@ -52,17 +53,25 @@ public static void StartAndWait(
5253
var percent = (int)(progress * 100.0);
5354
var r = new[] { "|", "/", "-", "\\" };
5455
var x = r[DateTime.Now.Second % 4];
55-
cmdlet.WriteProgress(
56-
new ProgressRecord(
57-
0,
58-
"Creating Azure resources",
59-
percent + "% " + x)
60-
{
61-
CurrentOperation = activeTasks.Count > 0
62-
? "Creating " + string.Join(", ", activeTasks) + "."
63-
: null,
64-
PercentComplete = percent,
65-
});
56+
var operation = activeTasks.Count > 0
57+
? "Creating " + string.Join(", ", activeTasks) + "."
58+
: null;
59+
60+
// write progress only if it's changed.
61+
if (x != previousX || operation != previousOperation)
62+
{
63+
cmdlet.WriteProgress(
64+
new ProgressRecord(
65+
0,
66+
"Creating Azure resources",
67+
percent + "% " + x)
68+
{
69+
CurrentOperation = operation,
70+
PercentComplete = percent,
71+
});
72+
previousX = x;
73+
previousOperation = operation;
74+
}
6675
}
6776
});
6877
}

0 commit comments

Comments
 (0)