Mainly completed using System. Threading. Timer
Planning
/// <Summary>
/// Planning
/// </Summary>
Public class Schedule {
/// <Summary>
/// Whether to execute the command immediately
/// </Summary>
Public bool IsImmediately {
Get {return _ isImmediately ;}
}
Private bool _ isImmediately;
/// <Summary>
/// Time difference from the next execution (if it is immediate execution, the return time difference is 0)
/// </Summary>
Public TimeSpan DueTime {
Get {
If (_ isImmediately ){
Return TimeSpan. Zero;
}
Else {
TimeSpan dueTime = _ executionTime-DateTime. Now;
While (dueTime. Ticks <0 ){
DueTime + = _ period;
}
Return dueTime;
}
}
}
/// <Summary>
/// Start time (if it is executed immediately, the current time is returned)
/// </Summary>
Public DateTime ExecutionTime {
Get {
If (_ isImmediately ){
Return DateTime. Now;
}
Else {
Return _ executionTime;
}
}
}
Private DateTime _ executionTime;
/// <Summary>
/// Running cycle
/// </Summary>
Public TimeSpan Period {
Get {return _ period ;}
}
Private TimeSpan _ period;
/// <Summary>
/// Execution at a certain time with a cycle
/// </Summary>
/// <Param name = "shedule"> scheduled time </param>
/// <Param name = "period"> period </param>