c# 任务计划
主要用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>
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,
部分文章来自网络,