日期:2014-05-17  浏览次数:20723 次

加上线程的事件就不能正常运行,怎么会呢?

namespace 事件驱动01
    {
    
    public partial class Form1 : Form
    {
        public event EventHandler doEvents;

        public Form1()
        {
            InitializeComponent();
        }
         private void button1_Click(object sender, EventArgs e)
        {
            runEvents();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //加上多线程操作时就不能执行
           System.Threading.Thread th2;
           th2 = new Thread(new ThreadStart(runEvents));
           th2.Start();
        }

        private void runEvents()
        {
            myEvent eX = new myEvent("Ok");

            if (doEvents != null)
            {
                doEvents(this, eX);
            }
        }
    }

    public class myEvent : EventArgs
    {
        public string EventName { get; set; }
        
        public myEvent(string prName )
        {
            this.EventName = prName;
        }
    }
}





        }
    }
}




namespace 事件驱动01
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Applica