为什么我的Azure WebJob应用程序中的TimerTrigger函数未被检测到?

Sco*_*don 4 c# azure azure-webjobs

我有一个Azure WebJob控制台应用程序,无法识别TimerTrigger我已设置.

我有Program.csVisual Studio生成的默认值:

class Program
{
  static void Main()
  {
    var config = new JobHostConfiguration();

    if (config.IsDevelopment)
    {
      config.UseDevelopmentSettings();
    }

    var host = new JobHost();

    host.RunAndBlock();
  }
}
Run Code Online (Sandbox Code Playgroud)

我将我的新功能添加到Functions.cs:

public static void MyFunction([TimerTrigger("0 */2 * * * *",
                                            RunOnStartup = true)]
                              TimerInfo timerInfo,
                              TextWriter log)
{
  log.WriteLine("MyFunction started!");
}
Run Code Online (Sandbox Code Playgroud)

(我安装了WebJobs.ExtensionsNuGet包,所以我的代码编译得很好.)

我还添加了这一行:

config.UseTimers();
Run Code Online (Sandbox Code Playgroud)

对于这个答案中Main提到的功能,但由于某种原因,我的新功能仍然没有被触发.

当我启动应用程序时,我看到了这个输出:

Found the following functions:
MyNamespace.Functions.ProcessQueueMessage
Job host started
Run Code Online (Sandbox Code Playgroud)

所以它没有看到我的新功能.

为什么会发生这种情况,我该如何解决?

Sco*_*don 10

在将我的内容与Program.cs其他人在网上发布的内容(包括TimerTrigger文档)进行比较后,我发现了一个小的差别.

Main函数中,我改变了:

var host = new JobHost();
Run Code Online (Sandbox Code Playgroud)

至:

var host = new JobHost(config);
Run Code Online (Sandbox Code Playgroud)

它起作用了.我确信之前没有更改过,所以显然这是Azure WebJob模板中的一个错误.

  • 对于面临此问题的其他任何人也是如此。.在Microsoft.Azure.WebJobs.Extensions nuget包中找到计时器触发器 (2认同)