当某些代码位于方法中时,Quartz.NET 不触发

发布于 2024-12-27 08:12:01 字数 899 浏览 5 评论 0原文

我正在尝试在 Azure 辅助角色中设置 Quartz.NET 来安排每日事件。经过多次试验和错误,我发现在目标方法中包含一行代码会导致事件根本无法触发

Quartz.NET 示例,我有一个 IJob 类,它覆盖了 Execute 方法(使用调度程序和触发器注册)。

当有问题的行(已注释)被删除时,我可以在 Trace.WriteLine 语句上命中断点。有了它,断点就永远不会被命中,并且输出不会出现在其他地方。

代码:

public class MyUpdaterJob : IJob
{
    public MyUpdaterJob()
    {
    }

    public void Execute(JobExecutionContext context)
    {
        Trace.WriteLine("-- Yay - Job called");

        // Removing this line will result in the breakpoint above being able to be hit
        MyUpdateWorker updateWorker = new MyUpdateWorker();

        var logDate = context.FireTimeUtc.Value.AddHours(-1);

        // [...]
    }
}

我对它可能正在评估什么导致它不触发此事件感到非常困惑。有什么建议吗?

  • “MyUpdateWorker”位于另一个库中,
  • 当前作为 Azure 辅助角色运行

I'm trying to set up Quartz.NET in an Azure worker role for scheduling a daily events. After much trial and error, I've found that the inclusion of one line of code within the target method is causing the event to not get triggered at all

Building off the Quartz.NET example, I have an IJob class the the overridden Execute method (registered with a scheduler & trigger).

When the offending line (commented) is removed, I can hit the breakpoint on the Trace.WriteLine statement. With it present, the breakpoint will never be hit, and the output isn't present elsewhere.

The code:

public class MyUpdaterJob : IJob
{
    public MyUpdaterJob()
    {
    }

    public void Execute(JobExecutionContext context)
    {
        Trace.WriteLine("-- Yay - Job called");

        // Removing this line will result in the breakpoint above being able to be hit
        MyUpdateWorker updateWorker = new MyUpdateWorker();

        var logDate = context.FireTimeUtc.Value.AddHours(-1);

        // [...]
    }
}

I'm at quite a loss as to what it might be evaluating that would cause it to not trigger this event. Any suggestions?

  • The 'MyUpdateWorker' is in another library
  • This is currently running as an Azure Worker Role

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云醉月微眠 2025-01-03 08:12:01

我想我会检查 MyUpdateWorker() 类的构造函数,看看是否一切正常,也许在诊断日志中有一个日志,看看是否可以在其中指出原因。通常我会看到 Azure 上缺少库的问题,因此可能缺少依赖项。

只需检查几件事(今天早上只喝了两杯咖啡,所以我还在热身中)

I think I'd check the constructor for your MyUpdateWorker() class to see if that all works ok, perhaps have a log at the diagnostic logs to see if you can something in there that would indicate the cause. Normally I see problems with missing libraries on Azure so perhaps there is a missing dependency.

Just a few things to check (only had two coffees this morning so I'm still warming up)

淡墨 2025-01-03 08:12:01

哇——这很奇怪。

由于该项目的“有机”增长,包含 IJob 实现的库以前是一个控制台应用程序,几周前我将其输出切换到“类库”。

平台目标设置为(仅可用)x86。其他一切都编译为“任何 CPU”,并且可能是 64 位。

我记得我必须手动编辑 .csproj 文件来更新它,但是一旦将 previous-console-project-now-library 设置为 Any CPU,它现在就会正确触发!

Wow - this was an odd one.

As a result of the 'organic' growth of this project, the library containing the IJob implementation was previously a console app, which I'd switched the output over to 'class library' a few weeks prior.

The Platform target was set to (any only had available) x86. Everything else was compiling as 'Any CPU', and probably 64 bit.

I recall I had to manually edit the .csproj file to update this, but once that former-console-project-now-library was set to Any CPU, it now triggers correctly!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文