【问题标题】:Scheduled Tasks - aspx page to be called at schedule time on server计划任务 - 在服务器上按计划时间调用的 aspx 页面
【发布时间】:2017-07-27 15:47:53
【问题描述】:

我有一个 asp.net 网站。现在我想在每天的特定时间调用一个.aspx 页面。 (没有 Window Scheduler/windows 服务)。

我想在没有 Window Scheduler 和 windows 服务的情况下完成此任务,因为某些客户端无法访问 Windows Server 内核/控制台,因此他们无法安装服务或 Window Task Scheduler

基本上, 我需要安排任务而不在 Windows 操作系统上安装任何东西。 没有 .exe 和窗口服务 因为我在网络场上托管应用程序 而且我不想有一台专用的窗口计算机来设置 exe 或 Windows 服务或 Window 任务计划程序来调用该 .aspx 页面

任何帮助将不胜感激!

谢谢

【问题讨论】:

    标签: c# asp.net windows scheduled-tasks web-farm


    【解决方案1】:

    花了大约 30-35 小时找到解决方案后,我找到了 quartz.dll 解决方法。它在C# 中可用。使用 Quartz,我们可以非常轻松地安排或致电任何JOB/C# function

    我们只需要在 Global.asax 文件中的 Application_Start 事件中启动我们的工作。

    为了更多的理解,你可以参考下面的代码,这对我来说是完美的!

    Gloabl.asax:-

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

    在 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);
    }
    

    在 JobSchedulerClass.cs 中:-

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

    【讨论】:

      【解决方案2】:

      试试hangfire,它是一个运行在 asp.net 上的作业处理器。

      代码会是这样的:

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

      【讨论】:

        猜你喜欢
        • 2012-10-13
        • 1970-01-01
        • 2011-03-29
        • 2011-07-05
        • 2012-02-12
        • 2018-04-04
        • 1970-01-01
        • 1970-01-01
        • 2012-05-23
        相关资源
        最近更新 更多