Timer传参问题

写一个Timer的类,里面定义需要传递的参数。
 class MyTimer : System.Timers.Timer
    {
        int id;
        public int GetId()
        {
            return id;
        }
        public void SetId(int value)
        {
            id = value;
        }
    }


static void Main(string[] args)
        {

            for (int i = 1; i <= 3; i++)
            {
                MyTimer taskTime = new MyTimer();

                taskTime.Interval =1000;
                taskTime.SetId(i);
                taskTime.Enabled = true;
                taskTime.AutoReset = true;

                taskTime.Elapsed += new System.Timers.ElapsedEventHandler(taskTime_Elapsed);
            }


            

            Console.WriteLine("over");
            Console.ReadLine();
        }
        static void taskTime_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            MyTimer t = (MyTimer)sender;
            Console.WriteLine(t.GetId());
            Console.ReadLine();
            t.Enabled = false;
            t.Close();
        }

资料参考:http://bbs.csdn.net/topics/390889626

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页