C#动态定时器+传参定时器

/*
 * Created by SharpDevelop.
 * User: Administrator
 * Date: 2013/11/23
 * Time: 21:30
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace 定时器
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		static int i=0;
		void MainFormLoad(object sender, EventArgs e)
		{
			//动态定时器
			int num=10;
			TaskTimer[] t=new TaskTimer[num];
			t[0]=new TaskTimer();
			t[0].Interval=1000;
			t[0].ID=0;
			t[0].Tick+= new EventHandler(theout);
			t[0].Start();
			
			t[1]=new TaskTimer();
			t[1].Interval=2000;
			t[1].ID=1;
			t[1].Tick+= new EventHandler(theout);
			t[1].Start();
		}
		public void theout(object source, EventArgs e) 
		{
					TaskTimer tt = (TaskTimer)source;
					MessageBox.Show(tt.ID.ToString());
		}

	}
	public class TaskTimer : Timer
 {
  #region <变量>
  /// <summary>
  /// 定时器id
  /// </summary>
  private int id;
  /// <summary>
  /// 定时器参数
  /// </summary>
  private  string param ;
  public static int num;
  #endregion

  #region <属性>
  /// <summary>
  /// 定时器id属性
  /// </summary>
  public int ID
  {
   set{id = value;}
   get{return id;}
  }
  /// <summary>
  /// 定时器参数属性
  /// </summary>
  public string Param 
  {
   set{param = value;}
   get{return param;}
  }
  
  #endregion
  ///<summary>
  /// 构造函数
  /// </summary>
  public TaskTimer() : base ()
  {

  }
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值