private void timer3_Tick(object sender, EventArgs e) { if (DateTime.Now.Hour % 2 != 0)//没个2小时 刷新一次服务器数据库 { timer3.Interval = 10 * 60 * 1000;//扫描频率一小时一次 } else { if (58 - DateTime.Now.Minute > 10)//当前时间 与设定时间相差10分以上 10分扫描一次 { timer3.Interval = 10 * 60 * 1000;//扫描频率设置为10分一次 } else { timer3.Interval = 1 * 60 * 1000;//当前时间与设定时间小于10分 1分钟扫描一次 if (DateTime.Now.Minute == 58) { string s = string.Empty;//本地发送账号id集合 DataTable dtAccount = EDMSendAccountBLL.GetUpdateAccountTable(sendEmailCount/5); for (int i = 0; i < dtAccount.Rows.Count; i++) { s += dtAccount.Rows[i]["id"].ToString() + ","; } s = s.Remove(s.LastIndexOf(","), 1); string ss = string.Empty;//本地已发送完成邮件id集合 DataTable dtEmail = EDMEmailSendBLL.GetUpdateEmailTable(); for (int i = 0; i < dtEmail.Rows.Count; i++) { ss += dtEmail.Rows[i]["id"].ToString() + ","; } ss = ss.Remove(ss.LastIndexOf(","), 1); EDMEmailSendBLL.UpdateSoMuch(dtEmail,ss); EDMSendAccountBLL.UpdateSoMuch(dtAccount,s); EDMEmailSendBLL.DelEDMEmailSendById(ss); EDMSendAccountBLL.DeleteEDMSendAccountByGroupId(s); } } } }
根据 当前时间的 时、分 分别动态设置不同的扫描频率 可减少扫描负担