简体   繁体   中英

Scheduled Tasks - aspx page to be called at schedule time on server

I have one asp.net web site. Now I want to have an .aspx page to be called at specific time everyday. ( Without Window Scheduler / windows service ).

I want to achieve this task without Window Scheduler and windows service because some client don't have access to Windows Server kernel/console So they can't install services or Window Task Scheduler

Basically, I need to have scheduled task WITHOUT installing anything on the Windows OS. No .exe nor window service because I host the app on a web farm and I don't want to have a dedicated window computer to set up the exe or windows service or Window Task Scheduler to call up that .aspx page

any help will be greatly appreciated !

Thank You

Try hangfire it's a job processor that run over asp.net.

Code will be like this:

RecurringJob.AddOrUpdate( () => YourJobHere(), Cron.Daily);

After spending around 30-35 hours to find the solution I found the quartz.dll to workaround. It is available in C# . Using Quartz we can schedule or call any JOB/C# function very easily.

We just need to initiate our job in Application_Start event from Global.asax file.

For more understanding you can refer below code which is working perfect for me !

Gloabl.asax: -

void Application_Start(object sender, EventArgs e)
{
  SchedulerUtil schedulerUtil = new SchedulerUtil();
  schedulerUtil.StartJob();
}

in Class SchedulerUtil.cs :-

public void StartJob()
{
  IScheduler iPageRunCodeScheduler;
  string SCHEDULE_RUN_TIME = "05:00"; // 05:00 AM
  // Grab the Scheduler instance from the Factory 
  iPageRunCodeScheduler = StdSchedulerFactory.GetDefaultScheduler();


  TimeSpan schedularTime = TimeSpan.Parse(SCHEDULE_RUN_TIME);
  iPageRunCodeScheduler.Start();
  DbCls obj = new DbCls();
  // define the job and tie it to our class
  DateTime scheduleStartDate = DateTime.Now.Date.AddDays((DateTime.Now.TimeOfDay > schedularTime) ? 1 : 0).Add(schedularTime);
  //IJobDetail job = JobBuilder.Create<Unity.Web.Areas.Admin.Controllers.CommonController.DeleteExportFolder>()
  IJobDetail job = JobBuilder.Create<JobSchedulerClass>() // JobSchedulerClass need to create this class which implement IJob
      .WithIdentity("job1", "jobGrp1")
      .Build();

  // Trigger the job to run now, and then repeat every 10 seconds
  ITrigger trigger = TriggerBuilder.Create()
      .WithIdentity("trigger1", "jobGrp1")
      //.StartNow()
      .StartAt(scheduleStartDate)
      .WithSimpleSchedule(x => x
          //.WithIntervalInHours(24)
          .WithIntervalInSeconds(15)
          .RepeatForever())
      .Build();

  // Tell quartz to schedule the job using our trigger
  iPageRunCodeScheduler.ScheduleJob(job, trigger);
}

In JobSchedulerClass.cs :-

  public class JobSchedulerClass : IJob
  {
    public void Execute(IJobExecutionContext context)
    {
      Common obj = new Common();
      obj.ScheduledPageLoadFunction();
    }
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM