chenpeng

C#窗体程序监听(亲身试用)
监听描述:public partial class Form1 : Form { public Form1...
扫描右侧二维码阅读全文
19
2020/01

C#窗体程序监听(亲身试用)

监听描述:


监听器是用来监听ServletContext (jsp application) 的生命周期的。
*当tomcat启动时 调用contextInitialized方法,用于创建spring的容器(webApplicationContext)
*当tomcat关闭时 contextDestroyed 调用容器里的close方法,关闭。

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);
            }
        }
    }

}
Last modification:January 19th, 2020 at 12:08 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment