2017-03-07 51 views
0

我有一個asp.net網站。現在我想每天在特定時間撥打.aspx頁面。 (無Window Scheduler/windows服務)。計劃任務 - 在服務器上安排時間調用aspx頁面

我要實現無窗Scheduler和窗口服務這個任務,因爲有些客戶沒有訪問到Windows Server內核/控制檯所以他們不能安裝的服務或Window任務計劃

基本上, 我需要沒有在Windows操作系統上安裝任何計劃任務。 沒有.exe文件,也不窗口服務 因爲我的主機上的網絡農場 的應用程序,我不希望有一個專門的窗口電腦設置的exe或Windows服務或Window任務計劃程序來調用一個.aspx

任何幫助將不勝感激!

謝謝

回答

2

嘗試hangfire它是在asp.net運行作業處理器。

代碼將是這樣的:

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

1

支出約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(); 
    } 
    }