7
7
using System ;
8
8
using System . Management . Automation ;
9
9
using Dbg = System . Management . Automation . Diagnostics ;
10
+ using System . Threading ;
10
11
11
12
12
13
namespace Microsoft . PowerShell
@@ -28,6 +29,12 @@ class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInt
28
29
// destroy the data structures representing outstanding progress records
29
30
// take down and destroy the progress display
30
31
32
+ if ( _progPaneUpdateTimer != null )
33
+ {
34
+ // Stop update 'ProgressPane' and destroy timer
35
+ _progPaneUpdateTimer . Dispose ( ) ;
36
+ _progPaneUpdateTimer = null ;
37
+ }
31
38
if ( _progPane != null )
32
39
{
33
40
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
64
71
65
72
if ( _progPane == null )
66
73
{
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.
69
78
70
79
_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
+ }
71
86
}
72
- _progPane . Show ( _pendingProgress ) ;
73
87
}
74
88
75
89
76
90
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
+
77
112
78
113
private
79
114
void
@@ -170,6 +205,9 @@ class ConsoleHostUserInterface : System.Management.Automation.Host.PSHostUserInt
170
205
171
206
private ProgressPane _progPane = null ;
172
207
private PendingProgress _pendingProgress = null ;
208
+ // The timer update 'ProgressPane' every 'UpdateTimerThreshold' milliseconds
209
+ private Timer _progPaneUpdateTimer ;
210
+ private const int UpdateTimerThreshold = 100 ;
173
211
}
174
212
} // namespace
175
213
0 commit comments