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

浙公网安备 33010602011771号