当前位置:编程学习 > C#/ASP.NET >>

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 © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,