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组件时,调用组件 ...
随机推荐
- ListView为什么用setOnItemClick这个方法和onTouch这个方法有冲突
因为如果onTouch方法中返回true的话,这次事件就被ListView中的item控件消费了,所以不会执行ListVIew的setOnItemClick这个方法了,如果onTouch方法返回fal ...
- 【博客迁移】hityixiaoyang.com
用了快两年简洁的cnblog现在迁移到新域名空间:http://blog.apluslogicinc.com 欢迎来踩啊~~~
- Masonry+Infinite-Scroll实现无刷新无分页完美瀑布流(转)
一.Masonry 是基于Jquery插件,用于对CSS布局的可移动层进行重新布局.Masonry愿意石工,可以这样形象的理解,页面上很多大小不一的移动层可以想象成散乱的石头,经过Masonry这个石 ...
- 优秀js插件收藏
1. 滚动视差效果,类似锤子主页等效果实现 https://github.com/hahnzhu/parallax.js 2. jQuery全屏滚动插件 http://www.dowebok.com/ ...
- 关于php配置文件
一:配置文件(php.ini)在 PHP 启动时被读取.对于服务器模块版本的 PHP,仅在 web 服务器启动时读取一次.对于 CGI 和 CLI 版本,每次调用都会读取. 二:Note that t ...
- 小白日记11:kali渗透测试之服务扫描-banner、dmitry、nmap特征库、操作系统识别、SNMP
服务扫描 不能单纯的以端口辨别服务.很多网络服务是漏洞频发的高危对象,对网络上的特定服务进行扫描,往往能让我们少走弯路,增加渗透成功的几率.确定开放端口后,通常会对相应端口上所运行服务的信息进行更深入 ...
- 开发技巧01——改变Toast显示位置
1.获得Toast对象——Toast toast = Toast.makeText(this, "Top Left!", Toast.LENGTH_SHORT); 2.Toast对 ...
- 最短路径之Dijkstra算法及实例分析
Dijkstra算法迪科斯彻算法 Dijkstra算法描述为:假设用带权邻接矩阵来表示带权有向图.首先引进一个辅助向量D,它的每个分量D[i]表示当前所找到的从始点v到每个终点Vi的最短路径.它的初始 ...
- Flex性能优化常用手法总结 转
转自:http://bbs.51aspx.com/showtopic-43693.html 随着Flex越来越多的被人们所熟知,越来越多的互联网也开始了RIA应用.众所周知,目前国内的宽带应用并不是像 ...
- ORA-01034: ORACLE not available
ora-01034:oracle not available ora-27101:shared mermory realm does not exist 解决办法: ...