1 draw Machine
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_01_ lottery Machine { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); Checkforillegalcrossthreadcalls=false; } Private voidButton1_Click (Objectsender, EventArgs e) { while(true) {Random R=NewRandom (); Label1. Text= R.next (0,Ten). ToString (); Label2. Text= R.next (0,Ten). ToString (); Label3. Text= R.next (0,Ten). ToString (); Thread.Sleep ( +); } } Private voidButton2_Click (Objectsender, EventArgs e) {Thread th=NewThread (() ={Random R=NewRandom (); while(true) {Label1. Text= R.next (0,Ten). ToString (); Label2. Text= R.next (0,Ten). ToString (); Label3. Text= R.next (0,Ten). ToString (); Thread.Sleep ( +); } }); Th. IsBackground=true; Th. Start (); } }}
View Code
2 Copy files
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.IO;usingSystem.Linq;usingSystem.Text;usingSystem.Threading;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_02_ file Copy { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidButton1_Click (Objectsender, EventArgs e) { //01 Creating ThreadsThread th =NewThread (() = { //perform file read and write operations//01-01 Read and read using(FileStream Fsreader =NewFileStream ("2015-04-14 Foundation Enhancement 1.rar", FileMode.Open)) { //01-02 Write and write using(FileStream fswrite =NewFileStream ("A.rar", FileMode.Create)) { LongCount =fsreader.length; LongCurrentcount =0; //set the length of each read byte[] bs =New byte[1024x768*1024x768]; intLen; while(len = Fsreader.read (BS,0Bs. Length)) >0) {Currentcount+=Len; Progressbar1.invoke (Newaction<int> ((XH) = {progressBar1.Value = XH;}), (int) (currentcount/count) * - ); Fswrite.write (BS,0, Len); } } } }); //02 Set as Background threadTh. IsBackground =true; //03 Startth. Start (); } }}
View Code
3
Step by step -65-thread small example