首页 > 解决方案 > .net core azure WebJob 3.0.3 UseTimers 丢失

问题描述

我正在尝试使用 .net core 2.1 设置新的网络UseTimers()作业,但在尝试配置作业时遇到了一个似乎丢失的问题。

在我的一生中,我似乎找不到任何可以为我指明正确方向的东西,因为文档似乎没有更新以反映使用HostBuilder而不是JobHostConfiguration.

我什至尝试过查看 WebJobs 扩展的源代码,但我似乎找不到任何帮助,我现在不知所措。

我有以下相当样板,但这仅在我不包含时才有效.UseTimers()

using System.Threading.Tasks; 
using Microsoft.Extensions.Configuration; 
using Microsoft.Extensions.Hosting; 
using Microsoft.Extensions.Logging; 
using Microsoft.Azure.WebJobs; 
using Microsoft.Azure.WebJobs.Extensions;

namespace marqueone.webjob 
{
    class Program
    {
        public static async Task Main(string[] args)
        {

            var builder = new HostBuilder()
            .UseEnvironment("Development")
            .ConfigureWebJobs(b =>
            {
                b.AddAzureStorageCoreServices()
                .AddAzureStorage();
            })
            .ConfigureAppConfiguration(b =>
            {
                b.AddCommandLine(args);
            })
            .ConfigureLogging((context, b) =>
            {
                b.SetMinimumLevel(LogLevel.Debug);
                b.AddConsole();
            })
            //.UseTimers()
            .UseConsoleLifetime();

            var host = builder.Build();
            using (host)
            {
                await host.RunAsync();
            }
        }
    } 
}

标签: c#azureazure-webjobsazure-webjobssdkazure-webjobs-triggered

解决方案


根据此链接,您应该使用 .AddTimers(),如以下代码:

.ConfigureWebJobs(config =>
{
    config.AddAzureStorageCoreServices();
    config.AddTimers();
})

而且在这个链接中,它解释了:

 in general all the previous config.UseXXX extension methods migrated to 

IHostBuilder builder.AddXXX methods.

推荐阅读