Case
I'm building REST API which should response at minimal possible time, also it should do some background work ASAP. Background work can take 10 seconds at max, but it's too much for API response time requirements.
It's .NET Core, running in Docker (linux) in Azure App Service.
I don't want use Hangfire or Quartz.NET, it's too heavy.
So I decided to do something like this
public async Task<bool> ReceiveAction(string id)
{
// do some async stuffs
#pragma warning disable 4014
Task.Factory.StartNew(async () => { await DoWork(); }, TaskCreationOptions.RunContinuationsAsynchronously);
#pragma warning restore 4014
return true;
}
Questions
Is it safe?
Is it good practice?
If not, what should I do different?