修复cron任务重复执行bug
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
|
||||
<Image Source="/Resource/Image/BacklogImg.png" Margin="22,35,22,361" />
|
||||
|
||||
|
||||
|
||||
<hc:Card MaxWidth="250" Height="200" BorderThickness="0" Effect="{DynamicResource EffectShadow2}" Margin="8">
|
||||
<!--Card 的内容部分-->
|
||||
<Border CornerRadius="4,4,0,0" Width="160" Height="160">
|
||||
|
||||
@@ -40,13 +40,15 @@ namespace GeekDesk.Control.Other
|
||||
if (info.ExecType == TodoTaskExecType.CRON)
|
||||
{
|
||||
CronExpression exp = new CronExpression(info.Cron);
|
||||
DateTime dtNow = DateTime.Now;
|
||||
DateTimeOffset ddo = DateTime.SpecifyKind(dtNow, DateTimeKind.Local);
|
||||
string nextExecTime = ddo.LocalDateTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
info.ExeTime = nextExecTime;
|
||||
DateTime nowTime = DateTime.Now;
|
||||
|
||||
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);
|
||||
if (minutes < 0)
|
||||
{
|
||||
@@ -62,7 +64,8 @@ namespace GeekDesk.Control.Other
|
||||
{
|
||||
Growl.SuccessGlobal("下次任务将在 " + minutes + " 分钟后提醒您!");
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
appData.ToDoList.Remove(info); //执行任务删除
|
||||
appData.HiToDoList.Add(info); //添加历史任务
|
||||
@@ -120,7 +123,7 @@ namespace GeekDesk.Control.Other
|
||||
ToDoInfo info = this.DataContext as ToDoInfo;
|
||||
int time = int.Parse(DelayTime.Text);
|
||||
string type = DelayType.Text;
|
||||
switch(type)
|
||||
switch (type)
|
||||
{
|
||||
case "分":
|
||||
info.ExeTime = DateTime.Now.AddMinutes(time).ToString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
Reference in New Issue
Block a user