线程避免winform窗体假死

using System.Threading;



private void Form1_Load(object sender, EventArgs e)

        {

            Thread thread = new Thread(conn);

            thread.Start();

        }



        private void conn()

        {

            for (int i = 0; i < 10; i++)

            {

                MessageBox.Show(i.ToString());

            }

            this.Invoke(new CallBack(DoCallBack),new object[] {true});

        }



        public void DoCallBack(bool isSuccess)

        {

            if (isSuccess)

	        {

                button1_Click(null, null);  

	        }

            else

            {

                MessageBox.Show("数据加载失败");

            }

        }



        public delegate void CallBack(bool isSuccess);



        private void button1_Click(object sender, EventArgs e)

        {

            MessageBox.Show("测试成功");

        }

 

你可能感兴趣的:(WinForm)