计划任务 - 在服务器上安排时间调用aspx页面
问题描述:
我有一个asp.net网站。现在我想每天在特定时间拨打.aspx
页面。 (无Window Scheduler/windows服务)。计划任务 - 在服务器上安排时间调用aspx页面
我要实现无窗Scheduler和窗口服务这个任务,因为有些客户没有访问到Windows Server内核/控制台所以他们不能安装的服务或Window任务计划
基本上, 我需要没有在Windows操作系统上安装任何计划任务。 没有.exe文件,也不窗口服务 因为我的主机上的网络农场 的应用程序,我不希望有一个专门的窗口电脑设置的exe或Windows服务或Window任务计划程序来调用一个.aspx
页
任何帮助将不胜感激!
谢谢
答
支出约30-35小时内找到解决方案后,我发现了quartz.dll要解决。它在C#
中可用。使用石英我们可以很容易地安排或调用任何JOB/C# function
。
我们只需要在Global.asax文件的Application_Start
事件中启动我们的工作。
欲了解更多了解,你可以参考下面的代码,这对我来说是完美的!
Gloabl.asax: -
void Application_Start(object sender, EventArgs e)
{
SchedulerUtil schedulerUtil = new SchedulerUtil();
schedulerUtil.StartJob();
}
在类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);
}
在JobSchedulerClass.cs: -
public class JobSchedulerClass : IJob
{
public void Execute(IJobExecutionContext context)
{
Common obj = new Common();
obj.ScheduledPageLoadFunction();
}
}