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组件时,调用组件 ...
随机推荐
- 如何知道PostgreSQL数据库下每个数据库所对应的目录
base目录,这是所有数据库目录的父目录. 在base目录下第一层,每个目录就是一个数据库所对应的文件. 那么如何知道哪个目录对应哪个数据呢? 查询如下:先看数据库列表 [pgsql@localhos ...
- Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理
B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/pr ...
- CDOJ 486 Good Morning 傻逼题
Good Morning Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/486 ...
- Lambda表达式实现有限状态机
实现状态机有多种模式,其中最灵活而强大的方式是通过迁移表来实现,该方式的缺点之一是需要编写大量小块代码去支持迁移表.而在C#3.0中,可以以一种非常优雅的方式实现. 除了有限状态机外,还有有限自动机, ...
- xcode 左边导航栏中,类文件后面的标记“A”,"M","?"……等符号的含义???
"M" = Locally modified "U" = Updated in repository "A" = Locally a ...
- SSL连接建立过程分析(1)
Https协议:SSL建立过程分析 web訪问的两种方式: http协议,我们普通情况下是通过它訪问web,由于它不要求太多的安全机制,使用起来也简单,非常多web网站也仅仅支持这样的方式下的訪问. ...
- php实现网页标签补全方法(转)
导读:PHP在生成静态文件的时候,有时候会因为一些混编问题让HTML标签不完整或混乱而导致页面混乱.作者分享下面这段小代码可以非常方便解决问题. 如果你的网页内容的html标签显示不全,有些表格标签不 ...
- php执行的困惑
最近在用php语言实现各种数据结构算法排序,可以说是很蛋疼的一件事,最近遇到了一个问题,不知道是什么原因,姑且放到这里,希望能看到的人予以帮助 首先我用php写了这样一个类 class ListNod ...
- PHP.7-HTML+CSS(一)-HTML语法、常用字符实体、颜色代码
HTML+CSS HTML是WEB页面的描述性语言,浏览器解释的语言 CSS则是为HTML制定样式的机制,为浏览器解释的语言.它不能独立使用,没有HTML就没有CSS,定义网页的外观和布局(字体.背景 ...
- python之装饰器详解
这几天翻看python语法,看到装饰器这里着实卡了一阵,最初认为也就是个函数指针的用法,但仔细研究后发现,不止这么简单. 首先很多资料将装饰器定义为AOP的范畴,也就是Aspect Oriented ...