0

We are developing a web application using ASP.NET Core MVC hosted inside IIS, which implement some business scenarios for CRM. But we have couple of background jobs and long running jobs to do synchronization with external systems. So not sure if those background jobs and the scheduled jobs are suitable to be running inside our ASP.NET Core MVC web application hosted inside IIS?

Now when we were developing "Classic" ASP.NET MVC (before the ASP.NET Core MVC), we were always told that such web projects are not designed for running long running tasks and/or scheduled tasks, where console applications are best for these types of tasks. For example IIS will go to sleep mode so background jobs might not get fired at the desired time if no one is using the web application + if we run long running tasks inside IIS they might get timed-out before the tasks complete.

So is the above case still valid inside ASP.NET Core MVC web projects? or the ASP.NET Core is suitable for running scheduled and/or long running tasks?

Thanks

John John
  • 1
  • 72
  • 238
  • 501
  • 2
    Not suitable. They still run in an IIS app pool, which is subject to being recycled and share CPU and RAM with your site. Creating a Windows Service hosting IHostedService inheritors is like five lines of code. – CodeCaster Oct 13 '21 at 09:52
  • It's been widely discussed in tons of threads, and if your project does not require too much reliability on those tasks you can go that route, https://blog.lextudio.com/unpleasant-facts-about-hangfire-632a3228ff8a – Lex Li Oct 13 '21 at 14:30
  • @CodeCaster thanks for the reply .. or i can use a console application which run on schedule basis using windows task scheduler instead of using windows service is this also a valid option ? – John John Oct 13 '21 at 15:06
  • 1
    Yes, setup a stand alone program and utility. It can be run by the server task scheduler every 1 hour, or every so often, or even be setup to start on server startup. However, if the process were to stop, how do you re-start? So as noted, better to build a server friendly program that is 100% separate from the web site. And such programs even allow you to subscribe say to folder events (someone - or even your web site might save some business document - the triggers to process files in that folder work nice with a separate program to do these kinds of things. So yes, create separate program – Albert D. Kallal Oct 13 '21 at 18:59
  • I think it is not suitable. If permission issues are involved in running a scheduled job, you also need to configure the identity of the application or application pool. If it is a highly authorized identity, there may be security issues. The second is the recovery and performance occupancy of the application pool. Recycling caused by high CPU or memory may miss the scheduled job time. – Bruce Zhang Oct 14 '21 at 06:13

0 Answers0