VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • 监听

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Dog dog = new Dog();
            InsertDog(dog);
            dog.OnAlert();
            //Console.WriteLine();
        }
        public void InsertDog(Dog dog)
        {
            dog.alertHandler += new Dog.AlEventHandler(HostEventHandler);
        }
        public void HostEventHandler(object sender, EventArgs e)
        {
            Console.WriteLine("{0}\n",sender.ToString());
        }
    }
    public class Dog
    {
        public delegate void AlEventHandler(object sender, EventArgs e);
        public event AlEventHandler alertHandler;
        protected  int tm = 0;
        public void OnAlert()
        {
            if(this.alertHandler!=null)
            {
                while (true)
                {
                    if (tm == 100)
                    {
                        this.alertHandler(this.tm, new EventArgs());
                        Console.WriteLine("2\n");
                        tm = 0;
                    }
                    tm++;
                    Thread.Sleep(10);
                }
            }
        }

    }
复制代码

相关教程