Azure Webjobs TimerTrigger无法正常工作

时间:2017-08-07 14:06:32

标签: c# azure azure-webjobs

我有这个非常简单的webjob

 class Program
{
    static void Main(string[] args)
    {
        JobHostConfiguration config = new JobHostConfiguration
        {
            StorageConnectionString = "mykey",
            DashboardConnectionString = "mykey"
        };

        config.UseTimers();

        JobHost host = new JobHost(config);
        host.RunAndBlock();
    }



    public static void EmailsConsumer([TimerTrigger("00:30:00", RunOnStartup = true)]TimerInfo ti)
    {
        //do something
    }
}

由于某种原因,它不会起作用 image

我做错了什么还是错误?

1 个答案:

答案 0 :(得分:2)

根据例外我们可以知道我们需要设置类public。请尝试添加public关键字然后它将起作用。

public class Program
    {
        static void Main(string[] args)
        {
            JobHostConfiguration config = new JobHostConfiguration
            {
                StorageConnectionString = "DefaultEndpointsProtocol=https;AccountName=storageAccountName;AccountKey=xxxxxx",
                DashboardConnectionString = "DefaultEndpointsProtocol=https;AccountName=storageAccountName;AccountKey=xxxx;"
            };

            config.UseTimers();

            JobHost host = new JobHost(config);
            host.RunAndBlock();
        }



        public static void EmailsConsumer([TimerTrigger("00:30:00", RunOnStartup = true)]TimerInfo ti)
        {
            //do something
        }
    }