user2868674 user2868674 - 4 years ago 92
ASP.NET (C#) Question

Setting an MVC ASP.NET application to do scheduled tasks - Method to achieve it?

I am building a website that will fetch data from xml feeds. I am building it as an MVC AP.NET application. I will need the application to get data from the xml files located on the provider's server every 2 minutes for example. These data will then be stored.
My problem is that I want these procedure to be done without interruption from the moment the website will be uploaded on server. I was thinking of using a timer in the main method(?) to get the data every 2 minutes. But I have searched other topics here and I found out that using AppFabric would be the solution. The problem is that I am an absolute beginner and I find it difficult to use it... Is there an other more simple way to achieve this continuous update of data from the xml file?

Answer Source

I would recommend you use Quartz to handle the scheduling instead of using the built-in timer. I have used Quartz in my last two projects and I have been very impressed. It can handle about any schedule you can think of.

Example Job Creation:

using Quartz;
using Quartz.Impl;

IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();

IJobDetail integrationJob = JobBuilder.Create<IntegrationJob>().Build();

ITrigger integrationTrigger = TriggerBuilder.Create()
            .WithSimpleSchedule(x => x.WithIntervalInSeconds(300).RepeatForever()).Build();

scheduler.ScheduleJob(integrationJob, integrationTrigger);

public class IntegrationJob : Ijob
    public void Execute(IJobExecutionContext context)
        //Write code for job
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download