/*
* 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 ()
{
}
}
}