Invoke Exercise

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void UpdateUI(string param1, string param2){
            this.textBox1.Text = param1 + param2;
        }
 
        public delegate void MyDelegate(string str1, string str2);
 
        public void NotifyUI()
        {
            if (this.InvokeRequired) {
                MyDelegate myDelegate = new MyDelegate(UpdateUI);
                this.Invoke(myDelegate, new Object[] { "TextBox", "Update" });
            }
        }
 
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            Thread thread = new Thread(new ThreadStart(NotifyUI));
            thread.Start();
        }
    }
}
posted @ 2013-08-29 15:53  Edinburgh  阅读(155)  评论(0)    收藏  举报