8000 Improve a progress pane performance (#2640) · PowerShell/PowerShell@760a9c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 760a9c2

Browse files
iSazonovlzybkr
authored andcommitted
Improve a progress pane performance (#2640)
* Improve a progress pane performance Add timer to update a progress pane every 100 ms
1 parent 35b844a commit 760a9c2

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterfaceProgress.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System;
88
using System.Management.Automation;
99
using Dbg = System.Management.Automation.Diagnostics;
10+
using System.Threading;
1011

1112

1213
namespace Microsoft.PowerShell
@@ -28,6 +29,12 @@ class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInt
2829
// destroy the data structures representing outstanding progress records
2930
// take down and destroy the progress display
3031

32+
if (_progPaneUpdateTimer != null)
33+
{
34+
// Stop update 'ProgressPane' and destroy timer
35+
_progPaneUpdateTimer.Dispose();
36+
_progPaneUpdateTimer = null;
37+
}
3138
if (_progPane != null)
3239
{
3340
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
6471

6572
if (_progPane == null)
6673
{
67-
// This is the first time we've received a progress record. Create a pane to show it, and
68-
// then show it.
74+
// This is the first time we've received a progress record.
75+
// Create a progress pane,
76+
// then show it,
77+
// then create and start timer to update it.
6978

7079
_progPane = new ProgressPane(this);
80+
81+
if (_progPaneUpdateTimer == null && _progPane != null)
82+
{
83+
_progPane.Show(_pendingProgress);
84+
_progPaneUpdateTimer = new Timer( new TimerCallback(ProgressPaneUpdateTimerElapsed), null, UpdateTimerThreshold, Timeout.Infinite);
85+
}
7186
}
72-
_progPane.Show(_pendingProgress);
7387
}
7488

7589

7690

91+
/// <summary>
92+
///
93+
/// TimerCallback for _progPaneUpdateTimer to update 'ProgressPane' and restart the timer.
94+
///
95+
/// </summary>
96+
97+
private
98+
void
99+
ProgressPaneUpdateTimerElapsed(object sender)
100+
{
101+
if (_progPane != null)
102+
{
103+
_progPane.Show(_pendingProgress);
104+
}
105+
if (_progPaneUpdateTimer != null)
106+
{
107+
_progPaneUpdateTimer.Change(UpdateTimerThreshold, Timeout.Infinite);
108+
}
109+
}
110+
111+
77112

78113
private
79114
void
@@ -170,6 +205,9 @@ class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInt
170205

171206
private ProgressPane _progPane = null;
172207
private PendingProgress _pendingProgress = null;
208+
// The timer update 'ProgressPane' every 'UpdateTimerThreshold' milliseconds
209+
private Timer _progPaneUpdateTimer;
210+
private const int UpdateTimerThreshold = 100;
173211
}
174212
} // namespace
175213

0 commit comments

Comments
 (0)
0