主要用System.Threading.Timer完成
計劃類/// <summary>
/// 計劃類
/// </summary>
public class Schedule {
/// <summary>
/// 是否立即執行
/// </summary>
public bool IsImmediately {
get { return _isImmediately; }
}
private bool _isImmediately;
/// <summary>
/// 離下次執行時間差(如果為立即執行,返回的時間差為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>
/// 開始運行的時間(如果是立即執行,返回為當前時間)
/// </summary>
public DateTime ExecutionTime {
get {
if (_isImmediately) {
return DateTime.Now;
}
else {
return _executionTime;
}
}
}
private DateTime _executionTime;
/// <summary>
/// 運行周期
/// </summary>
public TimeSpan Period {
get { return _period; }
}
private TimeSpan _period;
/// <summary>
/// 某一時間執行,有周期
/// </summary>
/// <param name="shedule">計劃執行的時間</param>
/// <param name="period">周期</param>