Preforming scheduled tasks in C# .NET MVC Application

南笙酒味 提交于 2019-11-29 08:13:50

You don't want to be performing long running and recurring background tasks in your web application for multiple reasons. You may go through the following blog post which outlines them very well.

I would recommend you moving this logic into a separate Windows Service or even a Console Application whose runs could be scheduled with the Windows Task Scheduler at the desired intervals.

The benefit of this is that you will be off-loading your web application from doing long running tasks which will be consuming precious resources from your webserver. Of course both the webserver and the worker service could share a common centralized datastore or messaging layer in order to communicate if necessary.

For scheduling tasks in ASP.NET MVC you have several options:

Be careful if you try to implement a custom solution yourself, as any exception in a thread not associated with a request would halt the entire process.

Visual Cron is a decent task scheduler you can use. We use it, calling service methods on our asp.net / mvc / webapi servers.

http://www.visualcron.com/

I had similar problem with my ASP.NET MVC App, I Wanted to do some works in special times and finally I could find a way. My solution was Plesk scheduels task feature, as where the most windows servers use plesk control panel You can publish your app on a windows server with plesk CP and create a new actionresualt in your MVC App and write Your codes that want to execute them in special times. By plesk scheduels tasks create a new task and call your Url with a cron that You made it, You can make many crons. If I Could not explain It very well You can search about Plesk Schedueled Tasks on the Internet, You can find many good answers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!