Skip to content

Instantly share code, notes, and snippets.

@schmitch
Last active October 7, 2019 10:41
Show Gist options
  • Save schmitch/60f870aeb6fb668fe304d959bb580e9e to your computer and use it in GitHub Desktop.
Save schmitch/60f870aeb6fb668fe304d959bb580e9e to your computer and use it in GitHub Desktop.
Is it possible
public class BackgroundQueuedHostedService : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
var workItem = await TaskQueue.DequeueAsync(cancellationToken);
await FastTask(); //
await Task.Factory.StartNew(
() =>
{
// Blocking call
},
CancellationToken.None,
TaskCreationOptions.LongRunning & TaskCreationOptions.DenyChildAttach,
TaskScheduler.Default);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment