前提是winform程序要开启运行,timer才会执行。
public TimeSpan fun()
{
System.DateTime currentTime = new System.DateTime();
currentTime = System.DateTime.Now;
DataTable dtMaxTime = BLL.XBC_Record.GetMaxTime();
DateTime historyTime = Convert.ToDateTime(dtMaxTime.Rows[0][0].ToString());
TimeSpan ts = currentTime - historyTime;
return ts;
}
以下有2个定时器:
private void timer2_Tick(object sender, EventArgs e)
{
TimeSpan ts = fun();
//每两分钟定时发送一次 发送的同时检测下最新数据记录 当这个发送的时间-最新记录