c# 定时器
关于c#中timer类 在c#里关于类就有3个
1.定义在system.windows.forms里
2.定义在system.threading.timer类里
3.定义在system.timers.timer类里
system.windows.forms.timer是应用于winform中的,他是通过windows实现的,类似于vb或delphi中的,内部使用api settimer实现的。他的主要缺点是计时不精确,而且必须有,console application(控制台应用程式)无法使用。
system.timers.timer和system.threading.timer很类似,他们是通过.net thread pool实现的,轻量,计时精确,对应用程式、消息没有特别的需要。system.timers.timer还能够应用于winform,完全取代上面的。他们的缺点是不支持直接的拖放,需要手工编码。关于c#中timer类 在c#里关于类就有3个
1.定义在system.windows.forms里
2.定义在system.threading.timer类里
3.定义在system.timers.timer类里
system.windows.forms.timer是应用于winform中的,他是通过windows实现的,类似于vb或delphi中的,内部使用api settimer实现的。他的主要缺点是计时不精确,而且必须有,console application(控制台应用程式)无法使用。
system.timers.timer和system.threading.timer很类似,他们是通过.net thread pool实现的,轻量,计时精确,对应用程式、消息没有特别的需要。system.timers.timer还能够应用于winform,完全取代上面的。他们的缺点是不支持直接的拖放,需要手工编码。
private void load() { system.timers.timer atimer = new system.timers.timer(); atimer.elapsed += new elapsedeventhandler(theout); //到达时间的时候执行事件; // 设置引发时间的时间间隔 此处设置为1秒(1000毫秒) atimer.interval = 100000; atimer.autoreset = true;//设置是执行一次(false)还是一直执行(true); atimer.enabled = true; //是否执行system.timers.timer.elapsed事件; } public void theout(object source, system.timers.elapsedeventargs e) { arraylist autotask = new arraylist(); autotask.add("8:30:00"); autotask.add("9:30:00"); autotask.add("10:30:00"); autotask.add("11:34:15"); for (int n = 0; n < 4; n++) { if (datetime.now.tolongtimestring().equals(autotask[n])) { messagebox.show("现在时间是" + autotask[n]); } } }
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论