0

The BackgroundService in Asp.Net Core 3.1 do not automatically start after I start / restart IIS. It needs manual http request call (browse from browser) to start.

Is there anything / any IIS configuration I am missing here?

Reyan Chougle
  • 4,917
  • 2
  • 30
  • 57
  • 1
    As far as I know, if you start or restart the IIS, it will not start the application immediately, it will start the application pool when the first request come in, this is IIS build-in feature. Here is a workaround, you should use [IIS Application Initialization](https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-application-initialization) to perform initialization tasks and "warm up" tasks for a web application to start the application. – Brando Zhang Dec 04 '20 at 07:35
  • @BrandoZhang Thanks brother, your comment helped me to get into right direction – Reyan Chougle Dec 04 '20 at 13:35
  • 1
    I'm glad that my comment has helped you. If you feel this comment is right enough, I will generate an answer. Please mark it as answer, so that other folks who faces the same issue could find the answer more easily. Thank you. – Brando Zhang Dec 07 '20 at 01:33

1 Answers1

1

It depends your implementation, did you write backgroundService start call in your startup? Personally I always write background service as a service never host them in IIS.

Cause don't know how is your design but this is expecting behavior of IIS. When you start the IIS it's actually starts to listen that port for http request and call your application's startup function. After the first http request coming through that site it's sending it to the application with new thread (this T time where your application truly run http flow).

Also background workers are not good for IIS, this answer explaining clearly.

Code snip will be more helpfull.

slhklc
  • 63
  • 1
  • 7