1. Call a method without Parameters Public class Program { Public static void process () { //...... } } Thread thread = new thread (New threadstart (threading. Process )); Thread. Start (); 2. Call a method with Parameters(. NET specifies that this method has only one parameter and must be of the object type) Public class Program { Public static void process (Object Data) { //...... } } List <string> DATA = new list <string> (); Data. Add (" "); Thread thread = new thread (New parameterizedthreadstart (parameters. Process )); Thread. Start (data ); 3. Call multiple parameters(With lambda expressions in. Net 3.5, you can easily call them) Public class Program { Public static void process (string P1, int P2) { //...... } } Thread thread = new thread () => {process. Process ("", 888 );}); Thread. Start (); The compiler converts a Lambda expression to an instance of the corresponding delegate type and generates a random method. We know that the thread constructor has two Delegate types: threadstart and parameterizedthreadstart, if it converts a Lambda expression to a threadstart instance, the compiler will compile it as follows:Code. Thread thread = new thread (New threadstart (TS); // generated by the compiler Thread. Start (); Threadstart Ts = new threadstart (isvalidxxxx); // generated by the compiler Public static void isvalidxxxx () // generated by the compiler { Worker. Process ("Jianghu kiddies", 888 ); } Note: The names of new variables or methods generated by the compiler are random. |