public class TimerHelper
{
System.Threading.Timer timer;
public TaskSendMMS tasksendmms { get; set; }
public void Start()
{
timer = new System.Threading.Timer(new TimerCallback(tasksendmms.Execute), null, , );
tasksendmms.timer = timer;
}
}
 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 != ) //如果该彩信 不是延迟发送的,直接退出.
{
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 = ;
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("=========================================结束执行计划========================================");
}
}
 /// <summary>
/// 启动执行计划
/// </summary>
/// <param name="MmsId"></param>
/// <param name="packageIDs"></param>
/// <param name="datetime"></param>
/// <returns></returns>
public int StartSendMMs(string MmsId, string packageIDs, string datetime)
{
TimerHelper timer = new TimerHelper();
timer.tasksendmms = new TaskSendMMS() { ExeTime = DateTime.Parse(datetime), MMSId = new Guid(MmsId), PhonePackageId = new Guid(packageIDs) };
timer.Start();
return ;
}

C# System.Threading.Timer 使用方法的更多相关文章

  1. System.Threading.Timer 定时器的用法

    System.Threading.Timer 是C# 中的一个定时器,可以定时(不断循环)执行一个任务.它是在线程上执行的,具有很好的安全性.为此  .Net Framework 提供了5个重载的构造 ...

  2. System.Threading.Timer使用心得

    System.Threading.Timer 是一个使用回调方法的计时器,而且由线程池线程服务,简单且对资源要求不高. "只要在使用 Timer,就必须保留对它的引用."对于任何托 ...

  3. System.Threading.Timer的使用技巧

    转自:http://www.360doc.com/content/11/0812/11/1039473_139824496.shtml# System.Threading.Timer timer = ...

  4. System.Threading.Timer如何正确地被Dispose

    System.Threading.Timer是.NET中一个定时触发事件处理方法的类(本文后面简称Timer),它背后依靠的是.NET的线程池(ThreadPool),所以当Timer在短时间内触发了 ...

  5. System.Windows.Forms.Timer、System.Timers.Timer、System.Threading.Timer的 区别和用法

    System.Windows.Forms.Timer执行的时候,如果你在过程中间加一个sleep整个的界面就死掉了,但是另外两个没有这个情况,System.Timers.Timer.System.Th ...

  6. c# 多线程之-- System.Threading Timer的使用

    作用:每隔多久去执行线程里的方法. class ThreadTimerDemo { static void Main(string[] args) { // Create an AutoResetEv ...

  7. 定时器:Timer:System.Threading.Timer类(转)

    最近的一个项目有一些地方需要用到定时功能,在设计过程中,突然发现.net的Timer类居然还有很多我以前没有用过的功能,这里就跟大家分享一下 注:这里的Timer类特指System.Threading ...

  8. .NET中System.Diagnostics.Stopwatch、System.Timers.Timer、System.Threading.Timer 的区别

    1.System.Diagnostics.Stopwatch Stopwatch 实例可以测量一个时间间隔的运行时间,也可以测量多个时间间隔的总运行时间. 在典型的 Stopwatch 方案中,先调用 ...

  9. System.Windows.Forms.Timer、System.Timers.Timer、System.Threading.Timer的差别和分别什么时候用

    System.Windows.Forms.Timer.System.Timers.Timer.System.Threading.Timer的 区别和用法http://space.itpub.net/1 ...

随机推荐

  1. HTML和CSS设置动态导航以及CSS中伪元素的简单说明

    HTML页面代码: <!DOCTYPE html> <html> <head> <title>Test</title> <meta c ...

  2. 20151207Study

    Liberal lawmakers proposed a bill to reduce the cost of medicine for older Americans.自由主义立法者提出一条减少老年 ...

  3. UIMenuController 弹出菜单框

    弹出菜单框 UIMenuItem *menuItem1 = [[UIMenuItem alloc] initWithTitle:@"删除" action:@selector(del ...

  4. Java getResourceAsStream() 方法会缓存文件的问题

    xxx.getClass().getClassLoader().getResourceAsStream("d:/test-config.properties") 这方法确实会缓存文 ...

  5. RHEL7学习之NTP配置

    一,安装NTP [root@localhost ~]# yum install ntp Loaded plugins: product-id, subscription-manager This sy ...

  6. Spring+struts2的基础上继续加hibernate3的jar包

  7. [WPF]建立自适应窗口大小布局的WinForm窗口

    编写WinForm程序时,都会碰到一个问题.就是WinForm窗口在不同分辨率下的大小问题.举例说明,你编写的WinForm窗口在1024×768下是合适.匀称的.不过,如果用户的计算机的分辨率为14 ...

  8. 用Java导出为excel表格

    导出的是最基础的excel表格,没有任何样式. <input type="button" value="输出到Excel" onclick='output ...

  9. 解决php中json_decode的异常JSON_ERROR_CTRL_CHAR

    该字符中含了ASCII码ETB控制符,即\x17导致json解析失败 (截图中显示ETB是因为用了Sublime text2) 解决方法如下:去掉0-31的控制符再进行decode $result = ...

  10. group_concat函数详解

    来自: http://hchmsguo.iteye.com/blog/555543 MySQL中group_concat函数 完整的语法如下: group_concat([DISTINCT] 要连接的 ...