JobApp.cs
1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using Quartz;
using WebRepository;
namespace WebMvc
{
public static class JobApp
{
#region 增加计划
/// <summary>
/// 新增定时器任务
/// </summary>
/// <param name="Table_entity">任务实体</param>
public static void AddJob(IScheduler _sched, SysJob Table_entity)
{
try
{
string methodName = Table_entity.MethodName ?? "";
IJobDetail job = null;
//if (methodName.ToLower().Equals("ClearLogJob".ToLower()))
//{
// job = JobBuilder.Create<ClearLogJob>().WithIdentity(Table_entity.JobName).Build();
//}
//else if (methodName.ToLower().Equals("AGVJob".ToLower()))
//{
// job = JobBuilder.Create<AGVJob>().WithIdentity(Table_entity.JobName).Build();
//}
if (job != null)
{
var trigger = TriggerBuilder.Create().WithIdentity(Table_entity.JobName).WithCronSchedule(Table_entity.CronExpression).Build();
_sched.ScheduleJob(job, trigger).Wait();
}
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region 删除计划
/// <summary>
/// 删除定时器任务
/// </summary>
/// <param name="Table_entity">任务实体</param>
public static void DeleteJob(IScheduler _sched, SysJob Table_entity)
{
try
{
_sched.PauseTrigger(new TriggerKey(Table_entity.JobName)).Wait();
_sched.UnscheduleJob(new TriggerKey(Table_entity.JobName)).Wait();
_sched.DeleteJob(new JobKey(Table_entity.JobName)).Wait();
}
catch (Exception e)
{
throw e;
}
}
#endregion
}
}