gpt4 book ai didi

c# - Quartz.Net 2.0.1 触发器

转载 作者:太空宇宙 更新时间:2023-11-03 16:26:32 24 4
gpt4 key购买 nike

我有一个 Web 应用程序,我正在尝试设置一个触发器以在应用程序启动时启动,然后每 5 分钟触发一次

一切都在 Global.asax 中 - 似乎是放置它的正确位置:

public class Global : HttpApplication
{
public static StdSchedulerFactory SchedulerFactory;
public static IScheduler Scheduler;
public static ITrigger ImageTrigger;

protected void Application_Start(object sender, EventArgs e)
{
SchedulerFactory = new StdSchedulerFactory();
Scheduler = SchedulerFactory.GetScheduler();

Scheduler.Start();

ImageTrigger = TriggerBuilder.Create()
.WithIdentity("ImageTrigger", "Group1")
.StartNow()
.WithSimpleSchedule(x => x.RepeatForever().WithIntervalInMinutes(5))
.Build();

var imageJob = JobBuilder.Create<DownloadImages>()
.WithIdentity("DownloadImages" , "Group1")
.Build();
Scheduler.ScheduleJob(imageJob, ImageTrigger);
}
...
}

所以我假设有一个简单的时间表使用 .WithIntervalInMiniutes() 导致作业被调用或者它有很大的错误?

附言我也试过:

        AlertTrigger = TriggerBuilder.Create()
.WithIdentity("AlertTrigger", "Group1")
.StartNow()
.WithCronSchedule("0 0/1 * * * ?")
.Build();

然后对着电脑大喊大叫!

预先感谢您的帮助。

马特

最佳答案

我试过你的代码,它工作正常。
我不认为网络服务是运行预定作业的最佳选择,因为它的本质。

我建议您阅读 ASP.NET Application Life Cycle .

Application_Start

Called when the first resource (such as a page) in an ASP.NET application is requested. The Application_Start method is called only one time during the life cycle of an application. You can use this method to perform startup tasks such as loading data into the cache and initializing static values. You should set only static data during application start. Do not set any instance data because it will be available only to the first instance of the HttpApplication class that is created.

在 IIS 中运行的 ASP.NET 工作进程是 shutdown and recycled一段时间不活动后。不过,您可以更改此行为。

可以阅读另一篇有趣的文章here .

关于c# - Quartz.Net 2.0.1 触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12409711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com