From 760a9c2997148f32a0b763165a32647abe49b985 Mon Sep 17 00:00:00 2001 From: iSazonov Date: Wed, 9 Nov 2016 01:21:28 +0600 Subject: [PATCH] Improve a progress pane performance (#2640) * Improve a progress pane performance Add timer to update a progress pane every 100 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 d273c3d06a..7e3021841a 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs @@ -7,6 +7,7 @@ Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Management.Automation; using Dbg = System.Management.Automation.Diagnostics; +using System.Threading; namespace Microsoft.PowerShell @@ -28,6 +29,12 @@ namespace Microsoft.PowerShell // 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 @@ namespace Microsoft.PowerShell 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 @@ namespace Microsoft.PowerShell private ProgressPane _progPane = null; private PendingProgress _pendingProgress = null; + // The timer update 'ProgressPane' every 'UpdateTimerThreshold' milliseconds + private Timer _progPaneUpdateTimer; + private const int UpdateTimerThreshold = 100; } } // namespace