在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1 public class TimerHelper 2 { 3 System.Threading.Timer timer; 4 public TaskSendMMS tasksendmms { get; set; } 5 public void Start() 6 { 7 timer = new System.Threading.Timer(new TimerCallback(tasksendmms.Execute), null, 100, 30000); 8 tasksendmms.timer = timer; 9 } 10 } public class TaskSendMMS { public Guid MMSId { get; set; } public Guid PhonePackageId { get; set; } public DateTime ExeTime { get; set; } private log log = new log(); public System.Threading.Timer timer; public TaskSendMMS() { } public void Execute(object a) { try { log.writelog("=========================================开始执行计划========================================"); string Extime = ExeTime.ToString("MM-dd HH:mm"); string today = DateTime.Now.ToString("MM-dd HH:mm"); if (today.Equals(Extime))//如果时间是执行时间,则执 { log.writelog("执行时间到了,时间为:" + today); DataBase.DataClasses_MMSDataContext db = new DataBase.DataClasses_MMSDataContext(); var mms = db.MMS.Where(c => c.ID == this.MMSId).FirstOrDefault(); log.writelog("查询数据库MMS记录名称:" + mms.Title); if (mms.State != 2) //如果该彩信 不是延迟发送的,直接退出. { log.writelog("该彩信不是延迟发送的,直接退出"); if (null != timer) { log.writelog("该彩信不是延迟发送的,直接退出 并关闭timer"); timer.Dispose(); } } else { log.writelog("执行时间到了,开始调用Web接口立即发送彩信."); //发送彩信 Business.Start(this.MMSId.ToString(), this.PhonePackageId.ToString(), ""); log.writelog("调用接口成功,完成发送彩信."); mms.State = 1; db.SubmitChanges(); log.writelog("彩信状态,修改为1"); if (null != timer) { log.writelog("全部完成 并关闭timer"); timer.Dispose(); } } } else { log.writelog("执行时间未到! 时间为: " + today); } } catch (Exception ee) { log.writelog("出现异常信息:" + ee.Message); } log.writelog("=========================================结束执行计划========================================"); } } 1 /// <summary> 2 /// 启动执行计划 3 /// </summary> 4 /// <param name="MmsId"></param> 5 /// <param name="packageIDs"></param> 6 /// <param name="datetime"></param> 7 /// <returns></returns> 8 public int StartSendMMs(string MmsId, string packageIDs, string datetime) 9 { 10 TimerHelper timer = new TimerHelper(); 11 timer.tasksendmms = new TaskSendMMS() { ExeTime = DateTime.Parse(datetime), MMSId = new Guid(MmsId), PhonePackageId = new Guid(packageIDs) }; 12 timer.Start(); 13 return 0; 14 }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论