我正在使用Quartz.net庫的簡單調度程序。 我有7個不同的觸發器。順序是這樣的。Quartz.net並不總是工作
第一次:每120分鐘。
第二:每12小時。
第三:每5分鐘一次。
第四:每3分鐘一次。
第五:每29秒。
第六:每10秒鐘一次。
第七:每5秒鐘一次。
你看到它有點複雜。我有這樣的問題。第一觸發器需要每兩個小時工作一次。但經過幾次運行後,它自行停止。它根本不起作用。其他人正在工作,他們沒事。 我很抱歉我的英文不好。
private int bultengetir = 120; // min
private int baslayanmacsil = 29; //sec
private int kuponsonuclandir = 5;//5 min
private int canliorangetir = 10; //sec
private int canlimacgetir = 7; //sec
private int canlimacsil = 12;//hour
private int videoeslestir = 3; //min
private DateTimeOffset g_bultengetir = DateTimeOffset.UtcNow.AddMinutes(0);//10
private DateTimeOffset g_baslayanmacsil = DateTimeOffset.UtcNow.AddMinutes(5);//5
private DateTimeOffset g_canlimacgetir = DateTimeOffset.UtcNow.AddMinutes(10);//10
private DateTimeOffset g_canliorangetir = DateTimeOffset.UtcNow.AddMinutes(11);//55
private DateTimeOffset g_canlimacsil = DateTimeOffset.UtcNow.AddMinutes(12);//5
private DateTimeOffset g_kuponsonuclandir = DateTimeOffset.UtcNow.AddMinutes(15);//15
private DateTimeOffset g_videoeslestir = DateTimeOffset.UtcNow.AddMinutes(15);//7
public void RunJobs()
{
CanliMaclariGetir();
CanliOranlariGetir();
BultenGetir();
BaslayanMaclariSil();
CanliMaclariSil();
KuponlariSonuclandir();
VideoEslestir();
}
private void BultenGetir()
{
try
{
ISchedulerFactory schfack = new StdSchedulerFactory();
IScheduler scheduler = schfack.GetScheduler();
IJobDetail jobdetay = JobBuilder.Create<BultenGetir>()
.WithIdentity("bultengetir")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithSimpleSchedule(s => s.WithIntervalInMinutes(bultengetir).RepeatForever())
.StartAt(g_bultengetir)
.Build();
scheduler.ScheduleJob(jobdetay, trigger);
scheduler.Start();
Log log = new Log()
{
Name = "BultenGetir Görev Emri",
Description = "BultenGetir Görev Emri Verildi.",
Start = DateTime.Now,
Finish = DateTime.Now,
TotalMilliSecond = 0,
Type = 6
};
DbWork db = new DbWork();
db.LogEkle(log);
}
catch (Exception ex)
{
string h_mesaj = ex.Message.ToString();
string icerik = "";
if (ex.InnerException != null) { icerik = ex.InnerException.ToString(); }
string h_yer = ex.StackTrace.ToString();
dal.HataEkle("", "Gorevler Katmanı > Gorev_Zamanlayici.cs", "BultenGetir()", DateTime.Now, h_mesaj, icerik, h_yer);
}
}
private void BaslayanMaclariSil()
{
try
{
ISchedulerFactory schfack = new StdSchedulerFactory();
IScheduler scheduler = schfack.GetScheduler();
IJobDetail jobdetay = JobBuilder.Create<BaslayanMaclariSil>()
.WithIdentity("baslayansil")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithSimpleSchedule(s => s.WithIntervalInSeconds(baslayanmacsil).RepeatForever())
.StartAt(g_baslayanmacsil)
.Build();
scheduler.ScheduleJob(jobdetay, trigger);
scheduler.Start();
Log log = new Log()
{
Name = "BaslayanMaclariSil Görev Emri",
Description = "BaslayanMaclariSil Görev Emri Verildi.",
Start = DateTime.Now,
Finish = DateTime.Now,
TotalMilliSecond = 0,
Type = 6
};
DbWork db = new DbWork();
db.LogEkle(log);
}
catch (Exception ex)
{
string h_mesaj = ex.Message.ToString();
string icerik = "";
if (ex.InnerException != null) { icerik = ex.InnerException.ToString(); }
string h_yer = ex.StackTrace.ToString();
dal.HataEkle("", "Gorevler Katmanı > Gorev_Zamanlayici.cs", "BaslayanMaclariSil()", DateTime.Now, h_mesaj, icerik, h_yer);
}
}
private void KuponlariSonuclandir()
{
try
{
ISchedulerFactory schfack = new StdSchedulerFactory();
IScheduler scheduler = schfack.GetScheduler();
IJobDetail jobdetay = JobBuilder.Create<KuponlariSonuclandir>()
.WithIdentity("kuponsonuclandir")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithSimpleSchedule(s => s.WithIntervalInMinutes(kuponsonuclandir).RepeatForever())
.StartAt(g_kuponsonuclandir)
.Build();
scheduler.ScheduleJob(jobdetay, trigger);
scheduler.Start();
Log log = new Log()
{
Name = "KuponlariSonuclandir Görev Emri",
Description = "KuponlariSonuclandir Görev Emri Verildi.",
Start = DateTime.Now,
Finish = DateTime.Now,
TotalMilliSecond = 0,
Type = 6
};
DbWork db = new DbWork();
db.LogEkle(log);
}
catch (Exception ex)
{
string h_mesaj = ex.Message.ToString();
string icerik = "";
if (ex.InnerException != null) { icerik = ex.InnerException.ToString(); }
string h_yer = ex.StackTrace.ToString();
dal.HataEkle("", "Gorevler Katmanı > Gorev_Zamanlayici.cs", "KuponlariSonuclandir()", DateTime.Now, h_mesaj, icerik, h_yer);
}
}
private void CanliOranlariGetir()
{
try
{
ISchedulerFactory schfack = new StdSchedulerFactory();
IScheduler scheduler = schfack.GetScheduler();
IJobDetail jobdetay = JobBuilder.Create<CanliOranlar>()
.WithIdentity("canliorangetir")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithSimpleSchedule(s => s.WithIntervalInSeconds(canliorangetir).RepeatForever()).StartAt(g_canliorangetir).Build();
scheduler.ScheduleJob(jobdetay, trigger);
scheduler.Start();
Log log = new Log()
{
Name = "CanliOranlariGetir Görev Emri",
Description = "CanliOranlariGetir Görev Emri Verildi.",
Start = DateTime.Now,
Finish = DateTime.Now,
TotalMilliSecond = 0,
Type = 6
};
DbWork db = new DbWork();
db.LogEkle(log);
}
catch (Exception ex)
{
string h_mesaj = ex.Message.ToString();
string icerik = "";
if (ex.InnerException != null) { icerik = ex.InnerException.ToString(); }
string h_yer = ex.StackTrace.ToString();
dal.HataEkle("", "Gorevler Katmanı > Gorev_Zamanlayici.cs", "CanliOranlariGetir()", DateTime.Now, h_mesaj, icerik, h_yer);
}
}
private void CanliMaclariGetir()
{
try
{
ISchedulerFactory schfack = new StdSchedulerFactory();
IScheduler scheduler = schfack.GetScheduler();
IJobDetail jobdetay = JobBuilder.Create<CanliMaclar>()
.WithIdentity("canlimacgetir")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithSimpleSchedule(s => s.WithIntervalInSeconds(canlimacgetir).RepeatForever()).StartAt(g_canlimacgetir).Build();
scheduler.ScheduleJob(jobdetay, trigger);
scheduler.Start();
Log log = new Log()
{
Name = "CanliMaclariGetir Görev Emri",
Description = "CanliMaclariGetir Görev Emri Verildi.",
Start = DateTime.Now,
Finish = DateTime.Now,
TotalMilliSecond = 0,
Type = 6
};
DbWork db = new DbWork();
db.LogEkle(log);
}
catch (Exception ex)
{
string h_mesaj = ex.Message.ToString();
string icerik = "";
if (ex.InnerException != null) { icerik = ex.InnerException.ToString(); }
string h_yer = ex.StackTrace.ToString();
dal.HataEkle("", "Gorevler Katmanı > Gorev_Zamanlayici.cs", "CanliMaclariGetir()", DateTime.Now, h_mesaj, icerik, h_yer);
}
}
private void CanliMaclariSil()
{
try
{
ISchedulerFactory schfack = new StdSchedulerFactory();
IScheduler scheduler = schfack.GetScheduler();
IJobDetail jobdetay = JobBuilder.Create<CanliSil>()
.WithIdentity("canlimacsil")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithSimpleSchedule(s => s.WithIntervalInHours(canlimacsil).RepeatForever())
.StartAt(g_canlimacsil)
.Build();
scheduler.ScheduleJob(jobdetay, trigger);
scheduler.Start();
Log log = new Log()
{
Name = "CanliMaclariSil Görev Emri",
Description = "CanliMaclariSil Görev Emri Verildi.",
Start = DateTime.Now,
Finish = DateTime.Now,
TotalMilliSecond = 0,
Type = 6
};
DbWork db = new DbWork();
db.LogEkle(log);
}
catch (Exception ex)
{
string h_mesaj = ex.Message.ToString();
string icerik = "";
if (ex.InnerException != null) { icerik = ex.InnerException.ToString(); }
string h_yer = ex.StackTrace.ToString();
dal.HataEkle("", "Gorevler Katmanı > Gorev_Zamanlayici.cs", "CanliMaclariSil()", DateTime.Now, h_mesaj, icerik, h_yer);
}
}
private void VideoEslestir()
{
try
{
ISchedulerFactory schfack = new StdSchedulerFactory();
IScheduler scheduler = schfack.GetScheduler();
IJobDetail jobdetay = JobBuilder.Create<VideoEslestir>()
.WithIdentity("videoeslestir")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithSimpleSchedule(s => s.WithIntervalInMinutes(videoeslestir).RepeatForever())
.StartAt(g_videoeslestir)
.Build();
scheduler.ScheduleJob(jobdetay, trigger);
scheduler.Start();
Log log = new Log()
{
Name = "VideoEslestir Görev Emri",
Description = "VideoEslestir Görev Emri Verildi.",
Start = DateTime.Now,
Finish = DateTime.Now,
TotalMilliSecond = 0,
Type = 6
};
DbWork db = new DbWork();
db.LogEkle(log);
}
catch (Exception ex)
{
string h_mesaj = ex.Message.ToString();
string icerik = "";
if (ex.InnerException != null) { icerik = ex.InnerException.ToString(); }
string h_yer = ex.StackTrace.ToString();
dal.HataEkle("", "Gorevler Katmanı > Gorev_Zamanlayici.cs", "videoeslestir()", DateTime.Now, h_mesaj, icerik, h_yer);
}
}
後您使用 – Jinish
cron的表達式Quartz.net運行在網站的AppPool中。如果沒有流量,AppPool將會進入睡眠狀態,觸發器將不會被觸發。當池再次啓動時,定時器被重置。或者別的什麼東西導致了AppPool的回收,比如更改'bin'文件夾 – VDWWD
好的,我添加了源代碼。 –