【问题标题】:Error JobRunShell.cs not found at HttpContextWrapper在 HttpContextWrapper 找不到错误 JobRunShell.cs
【发布时间】:2017-07-11 17:22:01
【问题描述】:

我使用 Quartz .NET 每分钟执行一次代码,并在代码执行后刷新索引页面,Quartz 可以正常执行代码但在重定向到索引页面 (UI) 时出错。

完整的代码是:

Startup.cs

public void Configuration(IAppBuilder app)
{
    ConfigureAuth(app);

    try
    {
        // construct a scheduler factory
        ISchedulerFactory schedFact = new StdSchedulerFactory();

        // get a scheduler
        IScheduler sched = schedFact.GetScheduler();
        sched.Start();

        // define the job and tie it to our HelloJob class
        IJobDetail job = JobBuilder.Create<NotificationJob>()
            .WithIdentity("myJob", "group1")
            .Build();

        // Trigger the job to run now, and then every 60 seconds
        ITrigger trigger = TriggerBuilder.Create()
          .WithIdentity("myTrigger", "group1")
          .StartNow()
          .WithSimpleSchedule(x => x
              .WithIntervalInSeconds(60)
              .RepeatForever())
          .Build();

        sched.ScheduleJob(job, trigger);
    }
    catch (ArgumentException e) { }
}

NotificationJob.cs

public class NotificationJob : IJob
{
    public void Execute(IJobExecutionContext Context)
    {
       // Code execution logic here...

        // Redirect to Index page
        var context = new RequestContext(new HttpContextWrapper(System.Web.HttpContext.Current), new RouteData());
        var urlHelper = new UrlHelper(context);
        var url = urlHelper.Action("Index", "Home");
        System.Web.HttpContext.Current.Response.Redirect(url);
    }
}

new HttpContextWrapper 发生错误。 任何帮助表示赞赏。

【问题讨论】:

  • 你用 Nuget 引用 Quartz 了吗?
  • 是的@S.Dav 我正在使用 Nuget 来引用 Quartz。
  • 石英 2.x 还是 3?
  • @Rabban 它是 Quartz 2.5.0
  • 我猜这是你工作中的一个错误,与石英无关。调试你的NotificationJob,你会看到它会在哪里抛出异常,这是真正的问题。也许HttpContext 为空或类似的东西。

标签: c# asp.net-mvc model-view-controller quartz.net httpcontext


【解决方案1】:

Quartz 作业无法访问 HttpContext。它们在 HttpContext 之外的不同线程中工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-14
    • 1970-01-01
    相关资源
    最近更新 更多