from: http://blog.csdn.net/gongzhe2011/article/details/27351853
UsingSystem.Windows.Forms;usingSystem.Threading;usingSystem;namespacethreaddemo1{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Delegate voidAastrings);//Create a proxy Private voidForm1_Load (Objectsender, EventArgs e) {Thread Newthread=NewThread (NewThreadStart (Ttread)); Newthread. Start (); } voidTtread () {pri (" the"); } Private Delegate voidProgressbarshow (inti); Private voidpristringp) {BOOLName =richtextbox1.invokerequired; //MessageBox.Show (name. ToString ()); if(!richtextbox1.invokerequired)//determine if a request for wake-up is required, and if the control is in a thread with the main threads, it can be written as if (! invokerequired){loadthread (); } Else { //MessageBox.Show ("Not the same thread");AA A1 =NewAA (PRI); Invoke (A1,New Object[] {p});//To perform a wake-up Operation } } Private voidLoadthread () {strings =string. Empty; for(intb =0; b <10000; b++) { This. Showpro (b); S+=b.tostring (); } //MessageBox.Show ("Within the same thread");Loadrichebox (s); } voidSend () {Thread.CurrentThread.Abort (); } Private voidLoadrichebox (strings) {richTextBox1.Text=s; } Private voidShowpro (intvalue) { if( This. invokerequired) { This. Invoke (Newprogressbarshow (Showpro), value); } Else { This. progressBar1.Value =value; This. Label1. Text = value +"% processing ..."; } } }}
Go: C # updates the UI with a delegate (asynchronously loaded)