⚠ Deprecated: Legacy
Suggested alternative: MiniScheduler
C#延时队列,定时任务(支持Cron表达式),不支持分布式,支持失败重试,支持设置失败次数
$ dotnet add package DelayQueuesC#延时队列,是线程安全的,不支持分布式,支持失败重试,支持设置失败次数
软件架构说明
static void Main(string[] args)
{
IDelayQueue delayQueue = DefaultQueueFactory.CreateQueue(new QueueOptions() { EnableRetry = true });
delayQueue.Enqueue(new QueueItem()
{
TaskName = "Test01",
DelayTime = TimeSpan.FromSeconds(10),
DelayAction = () =>
{
Console.WriteLine("Test01 Action {0}", DateTime.Now.ToString());
return true;
}
});
delayQueue.Enqueue(new QueueItem<string>()
{
TaskName = "Test02",
DelayTime = TimeSpan.FromSeconds(16),
ActionData = "TestData",
EnableRetry = true,
DelayAction = (str) =>
{
Console.WriteLine("Test02 Action: {0}, Data: {1}", DateTime.Now.ToString(), str);
return false;
}
});
Console.ReadLine();
}