Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions csharp/snippets/redo/RedoContinuousViaFutures/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,10 @@ TaskScheduler taskScheduler
{
// loop through the example records and queue them up so long
// as we have more records and backlog is not too large
while (pendingFutures.Count < MaximumBacklog)
for (string redo = engine.GetRedoRecord();
redo != null;
redo = engine.GetRedoRecord())
{

// get the next redo record
string redo = engine.GetRedoRecord();

// check if no redo records are available
if (redo == null) break;

Task task = factory.StartNew(() =>
{
engine.ProcessRedoRecord(redo, SzNoFlags);
Expand All @@ -92,28 +87,32 @@ TaskScheduler taskScheduler

// add the future to the pending future list
pendingFutures.Add((task, redo));
}

do
{
// handle any pending futures WITHOUT blocking to reduce the backlog
HandlePendingFutures(pendingFutures, false);

// if we still have exceeded the backlog size then pause
// briefly before trying again
if (pendingFutures.Count >= MaximumBacklog)
// handle the pending futures as log as maximum backlog exceeded
for (int loop = 0;
pendingFutures.Count >= MaximumBacklog;
loop++)
{
try
// check if this is NOT our first iteration through the loop
if (loop > 0)
{
Thread.Sleep(HandlePauseTimeout);

}
catch (ThreadInterruptedException)
{
// do nothing
// if we still have exceeded the backlog size after the first
// loop iteration then pause briefly before trying again
try
{
Thread.Sleep(HandlePauseTimeout);

}
catch (ThreadInterruptedException)
{
// do nothing
}
}

// handle any pending futures WITHOUT blocking to reduce the backlog
HandlePendingFutures(pendingFutures, false);
}
} while (pendingFutures.Count >= MaximumBacklog);
}

// check if there are no redo records right now
// NOTE: we do NOT want to call countRedoRecords() in a loop that
Expand Down
Loading
Loading