1. a class that uses methods to transmit data to a thread.
// Data structure to be transmitted <br/> public struct data <br/>{< br/> Public String message; <br/>}</P> <p> // method of specific functions. Note that the object type <br/> static void threadmainwithupa (Object O) <br/>{< br/> data d = (data) O; <br/> console. writeline (D. message); <br/>}</P> <p> private void form1_load (Object sender, eventargs E) <br/>{< br/> // call <br/> data d = new data (); <br/> D. message = "OK message"; // assign a value to the data structure <br/> thread T1 = new thread (threadmainwithupa); <br/> t1.start (d); <br/>
2. If you are not too troublesome or have special requirements, you can also create a new class to provide data to the thread.
// This is a new class <br/> public class mythread <br/>{< br/> // The data to be uploaded, the class has become an attribute <br/> private string data; </P> <p> // constructor, no return value <br/> Public mythread (string data) <br/>{< br/> This. data = data; <br/>}</P> <p> // print and implement functions <br/> Public void printmess () <br/> {<br/> console. writeline ("The message is:" + data ); <br/>}< br/> // ======================== ======================================< br/> // load events in another class </P> <p> private void form1_load (Object sender, eventargs e) <br/>{< br/> // instantiate this class <br/> mythread my = new mythread ("babababa "); </P> <p> // open the thread. The parameter is the real method in this class. <br/> thread t2 = new thread (my. printmess); <br/> t2.start (); <br/>}</P> <p>