1 .system.windows.forms

 .system.threading.timer

 .system.timers.timer

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms; namespace winformTimer
{
public partial class Form1 : Form
{
//不精确
public System.Windows.Forms.Timer timerEve;
public Form1()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
} private void button1_Click(object sender, EventArgs e)
{
timerEve = new System.Windows.Forms.Timer();
timerEve.Interval = ;
timerEve.Tick += timerEve_Tick;
timerEve.Start();
} void timerEve_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
}
public System.Timers.Timer timeEveTwo;
private void button2_Click(object sender, EventArgs e)
{
//Thread thread = new Thread(new ParameterizedThreadStart(theout));
//thread.Start();
timeEveTwo = new System.Timers.Timer();
//到达时间,执行事件
timeEveTwo.Elapsed += new System.Timers.ElapsedEventHandler(theout);
//执行一次为false 一直执行为true
timeEveTwo.AutoReset = true;
timeEveTwo.Start(); }
public void theout(object source,System.Timers.ElapsedEventArgs e)
{
//if(label2.InvokeRequired)
//{
// Action<string> changetime = (s) => { label2.Text = s.ToString(); };
// label2.Invoke(changetime);
//}
//else
//{
label2.Text = DateTime.Now.ToString();
//}
}
//Callback:一个 TimerCallback 委托,表示要执行的方法。
//State:一个包含回调方法要使用的信息的对象,或者为空引用(Visual Basic 中为 Nothing)。
//dueTime:调用 callback 之前延迟的时间量(以毫秒为单位)。指定 Timeout.Infinite 以防止计时器开始计时。指定零 (0) 以立即启动计时器。
//Period:调用 callback 的时间间隔(以毫秒为单位)。指定 Timeout.Infinite 可以禁用定期终止。
public System.Threading.Timer threadtimer; private void button3_Click(object sender, EventArgs e)
{
threadtimer = new System.Threading.Timer(new TimerCallback(timecall),null,,);
}
private void timecall(object obj)
{
label3.Text = DateTime.Now.ToString();
}
}
}

三种timer控件的简单实例的更多相关文章

  1. 关于c#中的Timer控件的简单用法

    Timer控件主要会用到2个属性一个是Enabled和IntervalEnabled主要是控制当前Timer控件是否可用timer1.Enabled=false;不可用timer1.Enabled=t ...

  2. QT代理Delegates使用实例(三种代理控件)

    效果如下,在表格的单元格中插入控件,用Delegates方式实现 源代码如下: main.cpp文件 #include <QApplication>#include <QStanda ...

  3. 用Delphi实现文件下载的几种方法(三种使用控件的方法)

    有个API就是UrlDownloadToFile.不仅如此,Delphi的一些控件也可以轻松实现下载,如NMHTTP,指定NMHTTP1.InputFileMode := ture; 指定Body为本 ...

  4. ASP.NET AJAX入门系列(10):Timer控件简单使用

    本文主要通过一个简单示例,让Web页面在一定的时间间隔内局部刷新,来学习一下ASP.NET AJAX中的服务端Timer控件的简单使用. 主要内容 Timer控件的简单使用 1.添加新页面并切换到设计 ...

  5. Windows Phone中的几种集合控件

    前言 Windows Phone开发过程中不可避免的就是和集合数据打交道,如果之前做过WP App的开发的话,相信你已经看过了各种集合控件的使用.扩展和自定义.这些个内容在这篇博客里都没有,那么我们今 ...

  6. winform学习(11)Timer控件

    利用Timer控件制作简单的跑马灯: 拉一个Lable控件至窗体中心,Text内容为★▶◀★▶◀★▶◀★▶◀ 再拉一个Timer控件,属性Enabled设置为True(即开启控件),Interval设 ...

  7. Jquery如何序列化form表单数据为JSON对象 C# ADO.NET中设置Like模糊查询的参数 从客户端出现小于等于公式符号引发检测到有潜在危险的Request.Form 值 jquery调用iframe里面的方法 Js根据Ip地址自动判断是哪个城市 【我们一起写框架】MVVM的WPF框架(三)—数据控件 设计模式之简单工厂模式(C#语言描述)

    jquery提供的serialize方法能够实现. $("#searchForm").serialize();但是,观察输出的信息,发现serialize()方法做的是将表单中的数 ...

  8. 10、面向对象以及winform的简单运用(isMdicontainer的设置、timer控件进行倒计时的制作)

    IsMdicontainer的设置 这是对于整个窗体的设置,将一个窗体的IsMdicontainer设置为true之后,再打开新窗体便可以让新窗体被父容器包括在内. 操作方法: 1)先建立一个子窗体C ...

  9. C# Winfrom 简单的运用Timer控件

    注意,在使用DateAndTime时,需要添加引用 using Microsoft.VisualBasic;否则不可以计算时间之间的差值. using System; using System.Col ...

随机推荐

  1. 使用axis2进行WebService的开发

    使用axis2进行WebService的开发 Apache Axis2 是 Apache Axis SOAP 项目的后继项目.此项目是 Web 服务核心引擎的重要改进,目标是成为 Web 服务和面向服 ...

  2. Gym-101128D:Dice Cup

    题意 给你两个骰子,一个有n面,一个有m面,分别仍一次,求和的概率最大的值 分析 签到题 模拟就行 凑数才把这个题也发到博客上···· #include <cstdio> #include ...

  3. PHP 商城无限极分类

    无限极分类,用的是递归,在外部调用fen()方法即可 index是刚开始寻找的顶级分类,suo是为了在前端展示的时候缩进 ,$suo=){ 一个数组用来返回的 $t=[]; 这是查询数据库的所有内容 ...

  4. Topic modeling【经典模型】

    http://www.cs.princeton.edu/~blei/topicmodeling.html Topic models are a suite of algorithms that unc ...

  5. hibernate mapping文件中 xmlns会导致linq to xml 查询不到对应的节点

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. flex 布局的深入研究

    对于flex盒模型的设计期望 flex盒模型是被期望设计成 1:在任何流动的方向上(包括上下左右)都能进行良好的布局 2:可以以逆序 或者 以任意顺序排列布局 3:可以线性的沿着主轴一字排开 或者 沿 ...

  7. css总结2:Flex 布局教程:Flex 语法(转)

    Flex 布局教程:语法篇 网页布局(layout)是 CSS 的一个重点应用. 布局的传统解决方案,基于盒状模型,依赖 display 属性 + position属性 + float属性.它对于那些 ...

  8. yum 安装telnet

    检测是否安装 rpm -qa |grep telnet 安装 yum install xinetd yum install telnet-server yum -y install telnet 再次 ...

  9. C# 由范式编程==运算符引发对string内存分配的思考

    今天在看C#编程指南时(类型参数的约束http://msdn.microsoft.com/zh-cn/library/d5x73970.aspx)看到一段描述: 在应用 where T : class ...

  10. indexDB的使用和异步图片blob文件保存

    //调整webkit兼容性 var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || w ...