修复cron任务重复执行bug
This commit is contained in:
@@ -40,13 +40,15 @@ namespace GeekDesk.Control.Other
|
|||||||
if (info.ExecType == TodoTaskExecType.CRON)
|
if (info.ExecType == TodoTaskExecType.CRON)
|
||||||
{
|
{
|
||||||
CronExpression exp = new CronExpression(info.Cron);
|
CronExpression exp = new CronExpression(info.Cron);
|
||||||
DateTime dtNow = DateTime.Now;
|
DateTime nowTime = DateTime.Now;
|
||||||
DateTimeOffset ddo = DateTime.SpecifyKind(dtNow, DateTimeKind.Local);
|
|
||||||
string nextExecTime = ddo.LocalDateTime.ToString("yyyy-MM-dd HH:mm:ss");
|
|
||||||
info.ExeTime = nextExecTime;
|
|
||||||
|
|
||||||
DateTime nextTime = ddo.LocalDateTime;
|
//计算下次执行时间
|
||||||
TimeSpan ts = nextTime.Subtract(dtNow);
|
DateTime nextTime = DateTime.SpecifyKind(exp.GetNextValidTimeAfter(nowTime).Value.LocalDateTime, DateTimeKind.Local);
|
||||||
|
|
||||||
|
string nextTimeStr = nextTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
|
info.ExeTime = nextTimeStr;
|
||||||
|
|
||||||
|
TimeSpan ts = nextTime.Subtract(nowTime);
|
||||||
int minutes = (int)Math.Ceiling(ts.TotalMinutes);
|
int minutes = (int)Math.Ceiling(ts.TotalMinutes);
|
||||||
if (minutes < 0)
|
if (minutes < 0)
|
||||||
{
|
{
|
||||||
@@ -62,7 +64,8 @@ namespace GeekDesk.Control.Other
|
|||||||
{
|
{
|
||||||
Growl.SuccessGlobal("下次任务将在 " + minutes + " 分钟后提醒您!");
|
Growl.SuccessGlobal("下次任务将在 " + minutes + " 分钟后提醒您!");
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
appData.ToDoList.Remove(info); //执行任务删除
|
appData.ToDoList.Remove(info); //执行任务删除
|
||||||
appData.HiToDoList.Add(info); //添加历史任务
|
appData.HiToDoList.Add(info); //添加历史任务
|
||||||
@@ -120,7 +123,7 @@ namespace GeekDesk.Control.Other
|
|||||||
ToDoInfo info = this.DataContext as ToDoInfo;
|
ToDoInfo info = this.DataContext as ToDoInfo;
|
||||||
int time = int.Parse(DelayTime.Text);
|
int time = int.Parse(DelayTime.Text);
|
||||||
string type = DelayType.Text;
|
string type = DelayType.Text;
|
||||||
switch(type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case "分":
|
case "分":
|
||||||
info.ExeTime = DateTime.Now.AddMinutes(time).ToString("yyyy-MM-dd HH:mm:ss");
|
info.ExeTime = DateTime.Now.AddMinutes(time).ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|||||||
Reference in New Issue
Block a user