弱鸡3,C# 一个Timer在等待过程中,interval被改变,时间如何处理,
2017-09-08 17:53
561 查看
using System; using System.Threading; using System.Timers; using Timer = System.Timers.Timer; namespace ConsoleApplication1 { class Program { private static Timer timer = new Timer(); static void Main(string[] args) { timer.Interval = 10000; timer.Elapsed += Print; timer.Start(); Thread thread = new Thread(NewThread); thread.Start(); Console.Read(); } private static void NewThread() { Console.WriteLine("进入线程,开始睡15S" + DateTime.Now.ToLocalTime()); Thread.Sleep(15000); Console.WriteLine("145 之后,将Interval置为13S,注意看下次执行时间" + DateTime.Now.ToLocalTime()); timer.Interval = 13000; } private static void Print(object sender, ElapsedEventArgs e) { Console.WriteLine(DateTime.Now.ToLocalTime()); } } }
Timer等待下一次事件执行,比如还有8S执行。
但此时如果将此Timer的interval改变为15S,则从此刻起,15S之后事件执行。
相关文章推荐
- C# Timer 控件 c#怎么获取timer剩余时间 倒计时数秒 如何获取 Interval 设置完的等待时间
- C# 对于执行时间较长函数,如何显示“处理中...”
- C# 如何生成一个时间戳
- c#如何使用webservice、存储过程及存储过程的创建(简单模仿类似QQ统计用户在线时间为例)
- 存储过程有输出参数,在c#中用nhibernate调用存储过程时,如何才能获取到一个结果集和这个输出参数呢?
- 在c#中如何动态改变iframe的src值,动态指向一个网页
- 在c#中如何动态改变iframe的src值,动态指向一个网页
- Tomcat如何处理一个HTTP请求的过程?
- C# 如何生成一个时间戳
- c# 导入excel 日期为整形如何处理?读出来是一个数值,如2008-08-08读出来是39688,怎样才能读出来是日期格式。
- 当JAVA WEB服务器端有一个执行时间长的方法,应该如何处理?
- 今天遇到一个问题:在程序中加入的定时触发器,当时出现这样一个问题,触发器定时2秒,程序从后台查询数据经过复杂处理后时间超过了2秒,我查阅好些网络上说有可能触发器等待程序执行完毕后,在触发下一次,也有说
- C# 在线程单独开一个等待窗体,并改变进度条的值【别扭】
- java中如何判断一个数是否为正整数(多种种方式比较有意思)对时间处理也可以
- 异常信息:CLR无法从COM 上下文0x645e18 转换为COM上下文0x645f88,这种状态已持续60秒。拥有目标上下文/单元的线程很有可能执行的是非泵式等待或者在不发送 Windows 消息的情况下处理一个运行时间非常长的操作.这种情况通常会影响到
- C# 如何生成一个时间戳
- C# 在线程单独开一个等待窗体,并改变进度条的值【别扭】
- C# 图像处理:记录图像处理时间的一个类
- C# 如何生成一个时间戳
- c#如何使用webservice、存储过程及存储过程的创建(简单模仿类似QQ统计用户在线时间为例)