Thread operations are primarily used in the thread class, which is defined under System.Threading.dll. You need to add this reference when you use it. This class provides us with four overloaded constructors (the following is quoted from MSDN). Thread (Parameterizedthreadstart) Initializes a new instance of the thread class, specifying the delegate to allow the object to be passed to the thread when it is started. thread (ThreadStart) Initializes a new instance of the thread class. Supported by the. NET Compact Framework. Thread (Parameterizedthreadstart, Int32) Initializes a new instance of the thread class, specifying the delegate to allow the object to be passed to the thread when it is started, and specifying the maximum stack size for the thread. thread (ThreadStart, Int32) Initializes a new instance of the thread class, specifying the maximum stack size of the threads. Supported by the. NET Compact Framework. If we define a thread with no parameters, we can use the ThreadStart with a parameterizedthreadstart with a parameter. Use a different method with multiple parameters, as described below. A using System with no parameters; Using System.Collections.Generic; Using System.Text; Using System.Threading; Namespace Aaaaaa { class AAA { & nbsp; public static void Main () { thread t = new Thread (new ThreadstarT (A)); T.start (); Console.read (); } private static void A () { Console.WriteLine ("Method a!"); } }} Results Show method A! with one parameter because the Parameterizedthreadstart requires that the parameter type must be object, the defined method B parameter type must be object. Using System; Using System.Collections.Generic; Using System.Text; Using System.Threading; Namespace Aaaaaa { class AAA { & nbsp; public static void Main () { Thread t = new Thread (new Parameterizedthreadstart (B)); T.start ("B"); Console.read (); } private static void B (Object obj) { Console.WriteLine ("Method {0}!", obj.) ToString ()); } }} results Show method B! Iii. with multiple parameters because thread defaults to provide only these two constructors, if you need to pass more than one argument, we can use the parameter as the property of the class ourselves. Instantiate the property when defining the object of the class, and then do the operation. Using System; Using System.Collections.Generic; Using System.Text; Using System.Threading; Namespace Aaaaaa { class AAA { public static void Main () { my m = new My (); m.x = 2; m.y = 3; thread t = new Thread (new ThreadStart (M.C)) ; T.start (); Console.read (); } } class my { public int x, y; public void C () { Console.WriteLine ("X={0},y ={1} ", This.x, This.y); } }} results show x=2,y=3 Four, use the structure body to pass the value to the parameter. Defines the public struct that you can define the parameters you need, and then, when you need to add a thread, you can define an instance of the struct body. Structural body struct Rowcol { public int row; nbsp; public int col; }; Define method public void Output (Object rc) { Rowcol rowcol = (rowcol) RC; for (int i = 0; i < rowcol.row i++) & nbsp; { for (int j = 0; j < Rowcol.col; j++) Console.Write ("{0}", _char); Console.Write ( "/n"); }
}