From d951d9dd24643a83ecdd56cad75bbc81551bbb83 Mon Sep 17 00:00:00 2001 From: iSazonov Date: Mon, 7 Nov 2016 16:36:53 +0300 Subject: [PATCH 1/2] Improve a progress pane performance Add timer to update a progress pane every 200 ms --- .../msh/ConsoleHostUserInterfaceProgress.cs | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs index d273c3d06a5..44ab8ad6e71 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 = 200; } } // namespace From 09de2db4f068c0bc8ddd416c14024d8e77537d61 Mon Sep 17 00:00:00 2001 From: Jason Shirk Date: Tue, 8 Nov 2016 11:00:38 -0800 Subject: [PATCH 2/2] Update every 100ms instead of 200ms --- .../host/msh/ConsoleHostUserInterfaceProgress.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs index 44ab8ad6e71..7e3021841a6 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs @@ -207,7 +207,7 @@ class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInt private PendingProgress _pendingProgress = null; // The timer update 'ProgressPane' every 'UpdateTimerThreshold' milliseconds private Timer _progPaneUpdateTimer; - private const int UpdateTimerThreshold = 200; + private const int UpdateTimerThreshold = 100; } } // namespace