阅读教程

C# Timer控件来实现定时触发事件

[日期:2008-06-19] 来源:  作者:志伟

<!--[if !supportLists]--> <!--[endif]-->使用C#Timer控件来实现定时触发事件,其主要参数如下:

Timer.Enabled 属性用于设置是否启用定时器

Timer.Interval 属性,事件的间隔,单位毫秒

Timer.Elapsed 事件,达到间隔时发生

示例:

  1. using System;   
  2.   
  3. using System.Collections.Generic;   
  4.   
  5. using System.Linq;   
  6.   
  7. using System.Text;   
  8.   
  9. using System.Timers;   
  10.   
  11.   
  12.   
  13. namespace ConsoleApplication1   
  14.   
  15. {   
  16.   
  17.     class Program   
  18.   
  19.     {   
  20.   
  21.         static void Main(string[] args)   
  22.   
  23.         {   
  24.   
  25.             System.Timers.Timer aTimer = new System.Timers.Timer();   
  26.   
  27.             aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);   
  28.   
  29.             // Set the Interval to 5 seconds.   
  30.   
  31.             aTimer.Interval = 5000;   
  32.   
  33.             aTimer.Enabled = true;   
  34.   
  35.   
  36.   
  37.             Console.WriteLine("Press \'q\' to quit the sample.");   
  38.   
  39.             while (Console.Read() != 'q') ;    
  40.   
  41.         }   
  42.   
  43.   
  44.   
  45.         private static void OnTimedEvent(object source, ElapsedEventArgs e)   
  46.   
  47.         {   
  48.   
  49.             Console.WriteLine("Hello World!");   
  50.   
  51.         }    
  52.   
  53.     }   
  54.   
  55. }  


      
      使用百度搜索:C# Timer控件来实现定时触发事件百度中搜索:C# Timer控件来实现定时触发事件
阅读:
录入:志伟

评论 】 【 推荐 】 【 打印
上一篇:如何使用C#实现对象的Xml格式序列化及反序列化
下一篇:SqlDataReader空字段的判断
本文评论       全部评论
  不错   (按时的 ,2008-07-23 )
发表评论


点评: 字数
姓名:

 
搜一下


 
本周热门教程
 

关于我们 | 广告合作 | 法律声明 | 联系站长 | 网站地图 | 网站搜索 | | Top ↑
Copyright © 志伟教程资料网 Powered by zhiweinet 1.0
 本栏目提供:C# Timer控件来实现定时触发事件