Suppress flow when queueing background threads
This commit is contained in:
@@ -66,7 +66,17 @@ public class ExamineIndexRebuilder : IIndexRebuilder
|
||||
_logger.LogInformation("Starting async background thread for rebuilding index {indexName}.", indexName);
|
||||
|
||||
_backgroundTaskQueue.QueueBackgroundWorkItem(
|
||||
cancellationToken => Task.Run(() => RebuildIndex(indexName, delay.Value, cancellationToken)));
|
||||
cancellationToken =>
|
||||
{
|
||||
// Do not flow AsyncLocal to the child thread
|
||||
using (ExecutionContext.SuppressFlow())
|
||||
{
|
||||
Task.Run(() => RebuildIndex(indexName, delay.Value, cancellationToken));
|
||||
|
||||
// immediately return so the queue isn't waiting.
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -96,12 +106,16 @@ public class ExamineIndexRebuilder : IIndexRebuilder
|
||||
_backgroundTaskQueue.QueueBackgroundWorkItem(
|
||||
cancellationToken =>
|
||||
{
|
||||
// This is a fire/forget task spawned by the background thread queue (which means we
|
||||
// don't need to worry about ExecutionContext flowing).
|
||||
Task.Run(() => RebuildIndexes(onlyEmptyIndexes, delay.Value, cancellationToken));
|
||||
// Do not flow AsyncLocal to the child thread
|
||||
using (ExecutionContext.SuppressFlow())
|
||||
{
|
||||
// This is a fire/forget task spawned by the background thread queue (which means we
|
||||
// don't need to worry about ExecutionContext flowing).
|
||||
Task.Run(() => RebuildIndexes(onlyEmptyIndexes, delay.Value, cancellationToken));
|
||||
|
||||
// immediately return so the queue isn't waiting.
|
||||
return Task.CompletedTask;
|
||||
// immediately return so the queue isn't waiting.
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user