我正在实施像方法这样的预定工作,并且已经缩小到方法的范围。一个实现定时器间隔,另一个基于任务延迟。
我也考虑过使用 Azure Timer 触发的 webjobs,但它们在多实例模式下不起作用。实际上,在多实例应用程序中,只有一个触发器在其中一个实例中被触发,而其他触发器被锁定,因此增加我的应用程序的实例计数并不会增加触发的事件数量。
方法A(定时器间隔)
using System;
using System.Threading.Tasks;
using System.Timers;
public class Example
{
public static void Main()
{
var aTimer = new Timer();
aTimer.Interval = 5000;
aTimer.Elapsed += OnTimedEventA;
aTimer.AutoReset = true;
aTimer.Enabled = true;
var bTimer = new System.Timers.Timer();
bTimer.Interval = 2000;
bTimer.Elapsed += OnTimedEventB;
bTimer.AutoReset = true;
bTimer.Enabled = true;
Console.WriteLine("Press the Enter key to exit the program at any time... ");
Console.ReadLine();
}
private static void OnTimedEventA(Object source, System.Timers.ElapsedEventArgs e)
{
Task.Run(() => …Run Code Online (Sandbox Code Playgroud) c# ×1