System.Windows.Forms.Timer
Windows 窗体 Timer 是定期引发事件的组件。该组件是为 Windows 窗体环境设计的。
时间间隔的长度由 Interval 属性定义,其值以毫秒为单位。若启用了该组件,则每个时间间隔引发一个 Tick 事件。
这是添加要执行的代码的位置。
Timer 组件的主要方法包括 Start 和Stop,这两种方法可打开和关闭计时器。计时器在关闭时重置;不存在暂停 Timer 组件的方法。
二、Windows 窗体 Timer 组件的 Interval 属性的限制
Windows 窗体 Timer 组件具有一个 Interval 属性,该属性指定一个计时器事件与下一个计时器事件之间间隔的毫秒数。
除非该组件被禁用,否则计时器会以大致相等的时间间隔继续接收 Tick 事件
Interval 属性:当编写 Timer 组件时,需要考虑 Interval 属性的几点限制:
如果应用程序或另一个应用程序对系统需求很大(如长循环、大量的计算或驱动程序、网络或端口访问),那么应用程序可能无法以 Interval 属性指定的频率来获取计时器事件。
间隔可以在 1 和 64,767 之间(包括 1 和 64,767),这意味着即使最长的间隔(大约 64.8 秒)也不会超过一分钟很多。
不能保证间隔所精确经过的时间。若要确保精确,计时器应根据需要检查系统时钟,而不是尝试在内部跟踪所积累的时间。
系统每秒生成 18 个时钟刻度,因此即使 Interval 属性以毫秒为单位,间隔的实际精度也不会超过十八分之一秒。
- System.Windows.Forms.Timer 类提供有关 Timer 类(用于 Windows 窗体计时器)及其成员的参考信息
private void InitializeTimer()
{
//' Run this procedure in an appropriate event.
// Set to 1 second.
Timer1.Interval = ;
// Enable timer.
Timer1.Enabled = true;
Button1.Text = "Stop";
} private void Timer1_Tick(object Sender, EventArgs e)
{
// Set the caption to the current time.
Label1.Text = DateTime.Now.ToString();
} private void Button1_Click()
{
if ( Button1.Text == "Stop" )
{
Button1.Text = "Start";
Timer1.Enabled = false;
}
else
{
Button1.Text = "Stop";
Timer1.Enabled = true;
}
}
2、第二个代码示例每隔 600 毫秒运行一次过程,直到循环完成时为止。
下面的代码示例要求您拥有一个窗体,该窗体具有一个名为 Button1 的 Button 控件、一个名为 Timer1 的 Timer 控件和一个名为 Label1 的 Label 控件。
// This variable will be the loop counter.
private int counter; private void InitializeTimer()
{
// Run this procedure in an appropriate event.
counter = ;
timer1.Interval = ;
timer1.Enabled = true;
// Hook up timer's tick event handler.
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
} private void timer1_Tick(object sender, System.EventArgs e)
{
if (counter >= )
{
// Exit loop code.
timer1.Enabled = false;
counter = ;
}
else
{
// Run your procedure here.
// Increment counter.
counter = counter + ;
label1.Text = "Procedures Run: " + counter.ToString();
}
}
详细信息查看:http://msdn.microsoft.com/zh-cn/library/beza71x7(v=vs.80).aspx
System.Windows.Forms.Timer的更多相关文章
- System.Windows.Forms.Timer与System.Timers.Timer的区别(zz)
.NET Framework里面提供了三种Timer: System.Windows.Forms.Timer System.Timers.Timer System.Threading.Timer VS ...
- System.Windows.Forms.Timer、System.Timers.Timer、System.Threading.Timer的 区别和用法
System.Windows.Forms.Timer执行的时候,如果你在过程中间加一个sleep整个的界面就死掉了,但是另外两个没有这个情况,System.Timers.Timer.System.Th ...
- 简述System.Windows.Forms.Timer 与System.Timers.Timer用法区别
System.Windows.Forms.Timer 基于窗体应用程序 阻塞同步 单线程 timer中处理时间较长则导致定时误差极大. System.Timers.Timer 基于服务 非阻塞异步 多 ...
- 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 ...
- System.Windows.Forms.Timer反编译学习
using System; using System.ComponentModel; using System.Globalization; using System.Runtime; using S ...
- System.Windows.Forms.Timer的简单用法
Timer就是用来计时操作,如:你想在多少秒之后执行某个动作 Timer showTextBoxTimer = new Timer(); //新建一个Timer对象 showTextBoxTimer. ...
- System.Windows.Forms
File: winforms\Managed\System\WinForms\DataGridView.cs Project: ndp\fx\src\System.Windows.Forms.cspr ...
- .net chart(图表)控件的使用-System.Windows.Forms.DataVisualization.dll
这个案例指在介绍微软这套免费又功能强大的图表控件Microsoft Chart Controls for Microsoft .NET Framework 3.5,通过它,可让您的项目及报表,轻松套用 ...
- WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常
WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常 在wpf中封装Com组件时,调用组件 ...
随机推荐
- hibernate一些坑记录集
1:对比原生sql查询和 hql查询 返回结果的类型 count: sql: select count(0) from xxx where .... 返回 BigInteger hql: select ...
- 使用EA逆向生成数据库E-R图
1. 创建ODBC数据源 2. 逆向工程
- 使用python selenium进行自动化functional test
Why Automation Testing 现在似乎大家都一致认同一个项目应该有足够多的测试来保证功能的正常运作,而且这些此处的‘测试’特指自动化测试:并且大多数人会认为如果还有哪个项目依然采用人工 ...
- C#使用SOAP获取webservice实例解析
本文主要參考例如以下两个链接.并整理: Java使用SOAP: http://www.cnblogs.com/linjiqin/archive/2012/05/07/2488880.html C# s ...
- 将Eclipse中现有的java类生成类图
需求:将Eclipse中现有的java类生成类图 一:什么是ModelGoon? 它是一个Eclipse插件,用于基于UML图的模型设计,以及逆向工程(即从已有源代码生成类图). 二:安装 下载Mod ...
- 琐碎-关于hadoop2.X那些端口
此文转载http://www.aboutyun.com/thread-7513-1-1.html Hadoop集群的各部分一般都会使用到多个端口,有些是daemon之间进行交互之用,有些是用于RPC访 ...
- Objective-C ,ios,iphone开发基础:几个常用类-NSString
第一个字符串: //必须在字符串的前面加上@符号, NSString* str=@"shouqiang_Wei";//输出以%@输出. NSLog(@"%@", ...
- 【约瑟夫环变形】UVa 1394 - And Then There Was One
首先看到这题脑子里立刻跳出链表..后来继续看如家的分析说,链表法时间复杂度为O(n*k),肯定会TLE,自己才意识到果然自个儿又头脑简单了 T^T. 看如家的分析没怎么看懂,后来发现这篇自己理解起来更 ...
- 简单遗传算法求解n皇后问题
版权声明:本文为博主原创文章,转载请注明出处. 先解释下什么是8皇后问题:在8×8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行.同一列或同一斜线上,问有多少种摆法.在不 ...
- less-1
说在前面的话,为什么用less: 1.需要编写的代码明显变少了 2.css管理更加容易 3.less学习成本低 4.使用less实现配色变得非常容易 5.兼容css3,实现各个浏览器中css的兼容写法 ...