One, without parameters of
usingSystem; usingSystem.Collections.Generic; usingSystem.Text; usingSystem.Threading; namespaceaaaaaa {classAAA { Public Static voidMain () {Thread T=NewThread (NewThreadStart (A)); T.start (); Console.read (); } Private Static voidA () {Console.WriteLine ("Method a!"); } } }
Two, with a parameter of the
Because Parameterizedthreadstart requires that the parameter type must be object, the defined method B parameter type must be object.
usingSystem; usingSystem.Collections.Generic; usingSystem.Text; usingSystem.Threading; namespaceaaaaaa {classAAA { Public Static voidMain () {Thread T=NewThread (NewParameterizedthreadstart (B)); T.start ("B"); Console.read (); } Private Static voidBObjectobj) {Console.WriteLine ("Method {0}!", obj. ToString ()); } } }
Three, with multiple parameters of the
Because thread provides only these two constructors by default, if you need to pass multiple arguments, we can use the parameters ourselves as properties of the class. This property is instantiated when the object of the class is defined and then manipulated.
usingSystem; usingSystem.Collections.Generic; usingSystem.Text; usingSystem.Threading; namespaceaaaaaa {classAAA { Public Static voidMain () {My m=NewMy (); M.x=2; M.y=3; Thread T=NewThread (NewThreadStart (M.C)); T.start (); Console.read (); } } classMy { Public intx, y; Public voidC () {Console.WriteLine ("X={0},y={1}", This. x, This. Y); } } }
usingSystem; usingSystem.Collections.Generic; usingSystem.Text; usingSystem.Threading; namespaceaaaaaa {classAAA { Public Static voidMain () {My m=NewMy (); M.x=2; M.y=3; Thread T=NewThread (NewThreadStart (M.C)); T.start (); Console.read (); } } classMy { Public intx, y; Public voidC () {Console.WriteLine ("X={0},y={1}", This. x, This. Y); } } }
Four, using the structure to give the parameter value.
Define common public structs, which define the parameters you need, and then define an instance of the struct when you need to add a thread.
/Structural BodystructRowcol { Public intRow; Public intCol; }; //Defining Methods Public voidOutput (Object rc) {rowcol rowcol=(rowcol) RC; for(inti =0; i < Rowcol.row; i++) { for(intj =0; J < Rowcol.col; J + +) Console.Write ("{0}", _char); Console.Write ("\ n"); } }
Threads thread, parameters and parameters