Azure Webjob 计时器触发异常
Azure Web Job Timmer trigger exception
我正在尝试使用 azure-webjobs-sdk-extensions (https://github.com/Azure/azure-webjobs-sdk-extensions)运行 触发 azure web 作业
JobHostConfiguration config = new JobHostConfiguration();
config.UseTimers();
JobHost host = new JobHost(config);
host.Call(typeof(Functions).GetMethod("CronJob"));
host.RunAndBlock();
public static void CronJob([TimerTrigger("0 */5 * * * *")] TimerInfo timer)
{
Console.WriteLine("Cron job fired!");
}
但是我遇到了这个异常。
Microsoft.Azure.WebJobs.Host System.ObjectDisposedException
我也尝试从该 gitbug 存储库下载示例项目,但即使使用那些 TimerTrigger 示例,我也遇到了同样的异常。
有什么想法吗?
谢谢
host.Call(typeof(Functions).GetMethod("CronJob"));
请注意,您应该为CronJob
函数提供一个TimerInfo
参数。 CronJob
函数由您定义的 TimeTrigger
自动调用。如果想在调用host.RunAndBlock()
之前调用CronJob
函数,可以参考下面的代码:
host.Call(typeof(Functions).GetMethod("CronJob"),new { timerInfo = new TimerInfo(null, null) });
But I'm getting this exception.Microsoft.Azure.WebJobs.Host System.ObjectDisposedException
根据您的描述,我从您提到的GitHub下载了示例工程,发现相关包的版本都比较旧。请按照此 tutorial to create an Azure WebJob project and install the latest version packages of Microsoft.Azure.WebJobs and Microsoft.Azure.WebJobs.Extensions,然后测试您的 TimeTrigger
功能。
我正在尝试使用 azure-webjobs-sdk-extensions (https://github.com/Azure/azure-webjobs-sdk-extensions)运行 触发 azure web 作业
JobHostConfiguration config = new JobHostConfiguration();
config.UseTimers();
JobHost host = new JobHost(config);
host.Call(typeof(Functions).GetMethod("CronJob"));
host.RunAndBlock();
public static void CronJob([TimerTrigger("0 */5 * * * *")] TimerInfo timer)
{
Console.WriteLine("Cron job fired!");
}
但是我遇到了这个异常。
Microsoft.Azure.WebJobs.Host System.ObjectDisposedException
我也尝试从该 gitbug 存储库下载示例项目,但即使使用那些 TimerTrigger 示例,我也遇到了同样的异常。
有什么想法吗? 谢谢
host.Call(typeof(Functions).GetMethod("CronJob"));
请注意,您应该为CronJob
函数提供一个TimerInfo
参数。 CronJob
函数由您定义的 TimeTrigger
自动调用。如果想在调用host.RunAndBlock()
之前调用CronJob
函数,可以参考下面的代码:
host.Call(typeof(Functions).GetMethod("CronJob"),new { timerInfo = new TimerInfo(null, null) });
But I'm getting this exception.Microsoft.Azure.WebJobs.Host System.ObjectDisposedException
根据您的描述,我从您提到的GitHub下载了示例工程,发现相关包的版本都比较旧。请按照此 tutorial to create an Azure WebJob project and install the latest version packages of Microsoft.Azure.WebJobs and Microsoft.Azure.WebJobs.Extensions,然后测试您的 TimeTrigger
功能。