@@ -73,15 +73,10 @@ TaskScheduler taskScheduler
73
73
{
74
74
// loop through the example records and queue them up so long
75
75
// as we have more records and backlog is not too large
76
- while ( pendingFutures . Count < MaximumBacklog )
76
+ for ( string redo = engine . GetRedoRecord ( ) ;
77
+ redo != null ;
78
+ redo = engine . GetRedoRecord ( ) )
77
79
{
78
-
79
- // get the next redo record
80
- string redo = engine . GetRedoRecord ( ) ;
81
-
82
- // check if no redo records are available
83
- if ( redo == null ) break ;
84
-
85
80
Task task = factory . StartNew ( ( ) =>
86
81
{
87
82
engine . ProcessRedoRecord ( redo , SzNoFlags ) ;
@@ -92,28 +87,32 @@ TaskScheduler taskScheduler
92
87
93
88
// add the future to the pending future list
94
89
pendingFutures . Add ( ( task , redo ) ) ;
95
- }
96
-
97
- do
98
- {
99
- // handle any pending futures WITHOUT blocking to reduce the backlog
100
- HandlePendingFutures ( pendingFutures , false ) ;
101
90
102
- // if we still have exceeded the backlog size then pause
103
- // briefly before trying again
104
- if ( pendingFutures . Count >= MaximumBacklog )
91
+ // handle the pending futures as log as maximum backlog exceeded
92
+ for ( int loop = 0 ;
93
+ pendingFutures . Count >= MaximumBacklog ;
94
+ loop ++ )
105
95
{
106
- try
96
+ // check if this is NOT our first iteration through the loop
97
+ if ( loop > 0 )
107
98
{
108
- Thread . Sleep ( HandlePauseTimeout ) ;
109
-
110
- }
111
- catch ( ThreadInterruptedException )
112
- {
113
- // do nothing
99
+ // if we still have exceeded the backlog size after the first
100
+ // loop iteration then pause briefly before trying again
101
+ try
102
+ {
103
+ Thread . Sleep ( HandlePauseTimeout ) ;
104
+
105
+ }
106
+ catch ( ThreadInterruptedException )
107
+ {
108
+ // do nothing
109
+ }
114
110
}
111
+
112
+ // handle any pending futures WITHOUT blocking to reduce the backlog
113
+ HandlePendingFutures ( pendingFutures , false ) ;
115
114
}
116
- } while ( pendingFutures . Count >= MaximumBacklog ) ;
115
+ }
117
116
118
117
// check if there are no redo records right now
119
118
// NOTE: we do NOT want to call countRedoRecords() in a loop that
0 commit comments