Skip to content

Instantly share code, notes, and snippets.

@fugaku
Created September 4, 2018 15:35
Show Gist options
  • Save fugaku/f2aa124a19c85ebcb4e30a63173a153f to your computer and use it in GitHub Desktop.
Save fugaku/f2aa124a19c85ebcb4e30a63173a153f to your computer and use it in GitHub Desktop.
Worker Hosted Service
public class WorkerHostedService : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stopToken)
{
//Do your preparation (e.g. Start code) here
while (!stopToken.IsCancellationRequested)
{
await DoSomethingAsync();
}
//Do your cleanup (e.g. Stop code) here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment