Example #1
0
        /// <summary>
        /// 测试事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEventTest_Click(object sender, EventArgs e)
        {
            CancellationTokenSource cts = new CancellationTokenSource();
            Heater heater = new Heater();

            //这里每次都重新定义一个heater并绑定一个方法到事件,实际运用中可在初始化时实例对象并绑定事件方法
            heater.HeaterEvent += (new HeaterEventTestClass(cts)).MakeAlarm;

            ThreadPool.QueueUserWorkItem(o => heater.Heat(cts.Token));
        }