gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:18:13 25 4
gpt4 key购买 nike

我的 Azure WebJob 控制台应用无法识别我设置的 TimerTrigger

我有 Visual Studio 生成的默认 Program.cs:

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

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

var host = new JobHost();

host.RunAndBlock();
}
}

我将新函数添加到 Functions.cs:

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

(我安装了 WebJobs.Extensions NuGet 包,因此我的代码可以正常编译。)

我还添加了这一行:

config.UseTimers();

this answer 中提到的 Main 函数,但由于某种原因,我的新功能仍然没有触发。

当我启动应用程序时,我看到以下输出:

Found the following functions:
MyNamespace.Functions.ProcessQueueMessage
Job host started

所以它看不到我的新函数。

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

最佳答案

将我的 Program.cs 内容与其他人在网上发布的内容(包括 the TimerTrigger docs )进行比较后,我发现了一些细微的差异。

Main函数中,我改变了:

var host = new JobHost();

至:

var host = new JobHost(config);

并且成功了。我确信我之前没有更改过这一点,所以显然这是 Azure WebJob 模板中的一个错误。

关于c# - 为什么我的 Azure WebJob 应用程序中的 TimerTrigger'd 函数未被检测到?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40895037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com