diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs index d273c3d06a5..7e3021841a6 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs @@ -7,6 +7,7 @@ using System; using System.Management.Automation; using Dbg = System.Management.Automation.Diagnostics; +using System.Threading; namespace Microsoft.PowerShell @@ -28,6 +29,12 @@ class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInt // destroy the data structures representing outstanding progress records // take down and destroy the progress display + if (_progPaneUpdateTimer != null) + { + // Stop update 'ProgressPane' and destroy timer + _progPaneUpdateTimer.Dispose(); + _progPaneUpdateTimer = null; + } if (_progPane != null) { Dbg.Assert(_pendingProgress != null, "How can you have a progress pane and no backing data structure?"); @@ -64,16 +71,44 @@ class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInt if (_progPane == null) { - // This is the first time we've received a progress record. Create a pane to show it, and - // then show it. + // This is the first time we've received a progress record. + // Create a progress pane, + // then show it, + // then create and start timer to update it. _progPane = new ProgressPane(this); + + if (_progPaneUpdateTimer == null && _progPane != null) + { + _progPane.Show(_pendingProgress); + _progPaneUpdateTimer = new Timer( new TimerCallback(ProgressPaneUpdateTimerElapsed), null, UpdateTimerThreshold, Timeout.Infinite); + } } - _progPane.Show(_pendingProgress); } + /// + /// + /// TimerCallback for _progPaneUpdateTimer to update 'ProgressPane' and restart the timer. + /// + /// + + private + void + ProgressPaneUpdateTimerElapsed(object sender) + { + if (_progPane != null) + { + _progPane.Show(_pendingProgress); + } + if (_progPaneUpdateTimer != null) + { + _progPaneUpdateTimer.Change(UpdateTimerThreshold, Timeout.Infinite); + } + } + + private void @@ -170,6 +205,9 @@ class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInt private ProgressPane _progPane = null; private PendingProgress _pendingProgress = null; + // The timer update 'ProgressPane' every 'UpdateTimerThreshold' milliseconds + private Timer _progPaneUpdateTimer; + private const int UpdateTimerThreshold = 100; } } // namespace