usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Threading;namespacewindowsformsapplication1{ Public Delegate voidRunhandler (Objecta,message mess); Public Delegate voidRunHandler1 (); Public Partial classform1:form {Thread th; Fox Fox; PublicForm1 () {InitializeComponent (); Fox=NewFox ("Xiao Zhi"); Label1. Text=Fox. Name; Fox. Runevent+=Fox_runevent1; Fox. RunEvent1+=Fox_runevent1; //button1. Click+=button1_click; } Private voidfox_runevent1 () {System.Threading.Thread.Sleep ( +);//One second delay if(textbox1.invokerequired) {RunHandler1 RH=NewRunHandler1 (Run); Textbox1.invoke (RH); } Else{TextBox1.Text="I went, the Lord of the Kinky"; } } Private voidFox_runevent1 (ObjectA, message mess) {TextBox2.Text="Come on! Pikachu"; } //private void Fox_runevent1 ()//{ //TextBox2.Text = "Pikachu"; //} //private void Fox_runevent ()//{ //TextBox1.Text = "Up bar"; //} classFox {Private string_name; Public stringName {Get{return_name;} Set{_name =value;} } PublicFox (stringname) {_name=name; } Public EventRunhandler runevent; Public EventRunHandler1 RunEvent1; Public voidbeshooted () {if(runevent!=NULL) {runevent ( This,NewMessage () {message="I went, the Lord of the Kinky"}); } } Public voidBeShooted1 () {if(runevent1!=NULL) {RunEvent1 (); } } } inti =0; Private voidButton1_Click (Objectsender, EventArgs e) { if(i==0) {Fox. Beshooted (); Th=NewThread (NewThreadStart (Run)); Th. Start (); I=1; } Else{TextBox1.Text=""; TextBox2.Text=""; I=0; } //th. Abort ();Button1. Text = button1. Text.equals ("Prepare") ?"swish.. ":"Prepare"; } Private voidRun () {Fox. BeShooted1 (); } Private voidForm1_Load (Objectsender, EventArgs e) { } } Public classMessage:eventargs { Public stringMessage {Get; Set; } }}
WPF multithreaded Operations (2)