-2

我的解决方案如下。请检查以下几点。

4

1 回答 1

2
  public class Program
  {
    public static void Main()
    {
        JobHostConfiguration config = new JobHostConfiguration();
        config.NameResolver = new TimeResolver();
        config.UseTimers();
        JobHost host = new JobHost(config);
        host.RunAndBlock();
    }

    private class TimeResolver : INameResolver
    {
        public string Resolve(string name)
        {
            string value = string.Empty;
            switch (name)
            {
                case "TimerJob":
                    Console.WriteLine("Name Is TimerJob : " + name);
                    value = "00:00:10";
                    break;
                case "TimerJobAlter":
                    Console.WriteLine("Name Is TimerJobAlter : " + name);
                    value = "00:00:20";
                    break;
            }
            return value;
        }
    }


    //Runs once every 30 seconds
    public static void TimerJob([TimerTrigger("%TimerJob%")] TimerInfo timer)
    {
        Console.WriteLine("Timer1 job fired!");
    }

    // Runs once every 60 seconds
    public static void TimerJobAlter([TimerTrigger("%TimerJobAlter%")] TimerInfo timer)
    {
        Console.WriteLine("Timer2 job fired!");
    }

}
于 2017-09-19T04:35:21.993 回答