0

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?

  • 2
    Make it a separate app. Used to be Worker role, and not sure what's its name now. – Lex Li Sep 19 '17 at 18:54
  • See this question: https://stackoverflow.com/questions/36945253/alternative-solution-to-hostingenvironment-queuebackgroundworkitem-in-net-core – viblo Nov 29 '17 at 12:59

0 Answers0