实现在用户定义的时间间隔引发事件的计时器。此计时器最宜用于 Windows 窗体应用程序中,并且必须在窗口中使用。
解决方案 »
- 如何监控多台PC上的共享文件夹和FTP文件是否存在超过5分钟的文件
- winform做好如何全部局域网用我的数据库?
- 资产价格波动计算器
- 当kill一个Excel以后,如何防止Process弹出一个Error的警告
- 求系统空闲时执行某个操作的方法
- Windows服务的问题(NT Service)超难,高手入
- 各位大哥大姐帮帮忙吧!!!!
- Ajax 有神经病!谁能看病呀?!?
- 请教关于dundas chart问题,怎么控制X轴显示,如显示一天中24小时,1,2,...24?
- 怎么取得dataSet中某行某列的值?
- ArrayList类的Item属性到底是怎么用得?急
- 写类关业输入属性的一个问题,很简单。
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;namespace TestThreadPool
{
class TimerExampleState
{
public int counter;
public Timer tmr;
}
class App
{
private static int _counter=0;
private static Timer _tmr; public static void Main()
{
//TimerExampleState s=new TimerExampleState(); // Create the delegate that invokes methods for the timer.
TimerCallback timerDelegate=new TimerCallback(CheckStatus);
// Create a timer that waits one second, then invokes every second.
_tmr=new Timer(timerDelegate,null,1000,1000); // Keep a handle to the timer, so it can be disposed.
//s.tmr=timer;
while(_tmr!=null)
Thread.Sleep(0);
Console.WriteLine("Timer example done.");
Console.ReadLine();
}
static void CheckStatus(object state)
{
//TimerExampleState s=(TimerExampleState)state;
_counter++;
Console.WriteLine("{0} Checking Status {1}",DateTime.Now.TimeOfDay,_counter);
if(_counter==5)
{
_tmr.Change(10000,100);
Console.WriteLine("Changed...");
}
if(_counter==10)
{
Console.WriteLine("Disposed");
_tmr.Dispose();
_tmr=null;
}
}
}
}