Scheduler for ASP.NET? - asp.net

I want to run some of my apps code every night in some sort of task or scheduler. Is there any build in functionality in the framework? If not, whats an easy 3rd party framework to get scheduling?
Thanks

You can create a console application and run it as a scheduled task. Alternatively you could look at using Quartz.Net which is a port of the Java Quartz, a framework for scheduling jobs.
Either way your finished product will likely be a console application that is scheduled to run with scheduled tasks, or a class library as a Windows Service. ASP.NET its self won't do the scheduling.

If you can, you could use IIS 7.5 Application Warm-Up Module : http://blogs.iis.net/thomad/archive/2009/10/14/now-available-the-iis-7-5-application-warm-up-module.aspx

Related

Trigger a Donet console application from outside the container

We have a requirement to trigger(using a JCL command) a Dotnet Core Console application (hosted on a PCF container) from outside the container. What would be a good solution approach in this context.
One option we have is to convert the console app into a web api and host an API endpoint which can be called from external sources. Web api can then trigger a long running task (may be use something like Hangfire to handle the execution). Would like to hear if there are better approaches that can be used here. Thanks in advance.
Cloud Foundry includes support for running tasks which might be all you need. Additionally, Steeltoe includes some functionality for building tasks into your application. There is a Steeltoe Sample that can run EntityFramework migrations via cf runtask

tools for running background tasks in asp.net mvc web application

I got confused on the correct design decision to execute background & long running tasks inside asp.net mvc web applications. now on these two links :-
http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx
&
http://haacked.com/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx/
they mentioned that it is risky to run background tasks and long running tasks inside asp.net web applications for the reasons they listed (mainly because IIS is not designed to run these types of tasks). but at the same time they listed some tools that can be installed inside the asp.net project to run background jobs such as quartz.net, WebBackgrounder , etc.
so i am not sure how these tool works ? for example if i install the WebBackgrounder inside my asp.net mvc web application (using nuget), and i deploy my asp.net mvc web application inside IIS ,, so will the jobs defined inside these tools run under IIS also ? or they will run independently of the IIs which is hosting the web application ?
They will run on IIS, but in a different thread. What you need to achieve? Maybe you're trying to solve a problem in the wrong place. Consider decouple this task from your web app using message queue. Then, construct a service to consume messages from queue and compute what you need.
Here's a sample using azure service bus and worker roles, but you can use the same idea on premises:
http://www.asp.net/aspnet/overview/developing-apps-with-windows-azure/building-real-world-cloud-apps-with-windows-azure/queue-centric-work-pattern
If you run Quartz.Net inside IIS then you're going to run into the same issues of IIS terminating the application periodically. When they mention using Quartz.Net what they are saying is that you install Quartz.Net as a windows service. Then your application talks to the Quartz.Net server that is running inside the service and schedules the jobs to run on it. The server/service then runs the jobs for you and you don't have the issues of running inside IIS, because your jobs are running inside the service.
There isn't a Quartz.Net nuget server package that can be installed as a windows service. For that you'll have to download the source and build it yourself or download the binaries from SourceForge. The Quartz.Net nuget package is what you will use to schedule the jobs from your web application to the Quartz.Net server.

How to perform daily maintenance on database records in MVC2 project?

A web application works with the database. Once a day, the database should be scanned and alerts should be sent to users.
From what I've seen out there, additional project has to be created which will be installed on the server and will work with the same database. Executable created by this project has to be installed in Windows scheduler to be activated once a day.
This seems complicated and inefficient: starting additional executable and working on the same database.
Is this the best possible way to do this?
Well you have different possibilities: Windows Scheduler with an executable is a good one. Another possibility is to write a Windows Service which will execute the task in the background. Quartz.NET is a good framework for this but the Windows Scheduler might be sufficient for your scenario. One thing is for sure: it is be better to perform these tasks outside of your ASP.NET application.

Scheduled tasks for ASP.NET

How to execute asp.NET code in scheduled task of windows?
I've often used wget / curl to do exactly this from windows scheduled tasks (or even from cron on a different server). For certain things it is better to keep it all within the web application.
e.g.
curl -k https://example.com/update.aspx?id=71077345 -u username:password
or
wget -O - http://example.com/process.php
ASP.Net has good integration with Windows Workflow (WF). I've accomplished 2 project with such integration. WF allows persists tasks, so it is independent on IIS restarting or system crash
The simplest and probably the easiest way to do this is to make the code a command line app and then execute it using the Windows Scheduler found in Control Panel.
If you have full access to the server, use the scheduled tasks.
If you do not have access (shared hosting), create a webpage/service that you can call to trigger the action. Be aware that the "action" is limited in time.
You could create a small application, that you can schedule on you own computer to call the remote server, to trigger the action.
There is no way to schedule ASP.NET code from within a web application, because the web is stateless.
My preferred method to schedule .NET code, is to write a windows service that I install on the web server. See. http://blog.dogma.co.uk/search/label/windowsservice.
An quicker, less efficient, way is to add the code to a page and execute that page from Windows Scheduled Tasks.
Rich

windows service versus asp.net Application_BeginRequest event with threads/timers

What are the advantages/disadvantages to running time based jobs using:
windows services
Application_BeginRequest to start seperate threads / timers.
One disadvantage of running the jobs in the context of a asp.net web appplication is during .net recycling things will have to be setup again, any others?
To my mind, there's no real benefit to doing time-based things in a web app. Go straight to a windows service. You know the process should be up and running all the time.
The ASP.NET site may simply unload, and will only operate again once someone starts browsing. The lifecycle is all wrong -- it's much 'choppier' than a service.
Lastly, services aren't very hard to create.
If you have administrative access to the server, I would either run a Windows Service or a scheduled SQL job depending on what you are trying to achieve.
It is nice to be able to stop/start and log these jobs independent of your web application. Also, if you have problems or errors in the job, it could adversely affect your website.
Finally, you are forcing the web application to go through code at every request to see if the timer has elapsed, which is an unnecessary overhead.
As I said to start with, the implementation depends on what the job is. If it is simply to update a number of database records, I'd use a scheduled job in SQL Server. If you need file I/O or access to external services, then a Windows Service might be more appropriate.
It is worth noting that you need to build in your own scheduling and thread safety into Windows Services. An alternative is to build a console application and use an application like FireDaemon for the scheduling.

Resources