/// <summary>
/// 满足条件后1秒钟执行
/// </summary>
public static System.Timers.Timer tXMGSZSJOA = new System.Timers.Timer(1000);//实例化timer类,设置间隔时间为6000毫秒(1秒钟);
/// <summary>
/// 对接定时器
/// </summary>
protected void InitXMGSZSJ()
{
E7HR.Model.SysParam mo = new E7HR.BLL.SysParam().GetModel(E7HR.Model.SysParam.SysParamType.Xitong, E7HR.Model.SysParam.ParaNames.WebCustom);
//执行条件
if (mo != null && mo.ParaValue == "定时器")
{
tXMGSZSJOA.Elapsed += new System.Timers.ElapsedEventHandler(XMGSZSJOA);//到达时间的时候执行事件;
tXMGSZSJOA.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
tXMGSZSJOA.Enabled = true;//是否执行system.timers.timer.elapsed事件;
tXMGSZSJOA.Interval = 1000 ;
}
else
{
tabControl1.TabPages.Remove(tabXMGSZSJ);
}
}
#region 数据对接
public static WindowsServer.QJJoin.KqJiaQinListJoin join = new WindowsServer.QJJoin.KqJiaQinListJoin();
public static void XMGSZSJOA(object source, System.Timers.ElapsedEventArgs e)
{
int intHour = e.SignalTime.Hour;
int intMinute = e.SignalTime.Minute;
int intSecond = e.SignalTime.Second;
// 设置 每天的7:00对接
if (intHour == 7 && intMinute == 00 && intSecond == 00)
{
join.InsertKqJiaQinList();
}
// 设置 每天的12:00对接
else if (intHour == 12 && intMinute == 00 && intSecond == 00)
{
join.InsertKqJiaQinList();
}
// 设置 每天的7:00对接
else if (intHour == 18 && intMinute == 00 && intSecond == 00)
{
join.InsertKqJiaQinList();
}
}
#endregion
然后在初始化里面调用InitXMGSZSJ()就可以。