Now C # is recommended to discard the use of suspend, resume pause/resume the thread, and use the abort method to interrupt a thread as little as possible.
We recommend that you use the following Thread Synchronization Methods: , , ,
Public thread (threadstart start );
The other is with parameters (parameterizedthreadstart delegate )--
Public thread (parameterizedthreadstart start );
Parameterizedthreadstart:
Public Delegate void parameterizedthreadstart (Object OBJ );
Example:
1. Without parameters:
// Define the thread method:
Private Static void threadmain ()
{
Console. writeline ("this is other thread main method .");
}
// Call:
Thread mythread = new thread (threadmain );
Mythread. Start ();
2. With parameters:
// Define the thread method:
Private Static void mainthreadwithparameters (Object O)
{
Data d = (data) O; // type conversion
Console. writeline ("running in a thread, received {0}", D. Message );
}
Public struct data
{
Public String message;
}
// Call:
VaR DATA = new data {message = "info "};
Thread t2 = new thread (Mainthreadwithparameters);
T2.start (Data);// Input parameters
3. PASS Parameters by defining classes:
// Define the classes for storing data and thread methods:
Public class mythread
{
Private string message;
Public mythread (string data)
{
This. Message = data;
}
Public void threadmethod ()
{
Console. writeline ("running in a thread, data: {0 }",This. Message);
}
}
// Call
var OBJ = new mythread ("info");
thread mythread = new thread ( obj. threadmethod ); // threadstart DeleGate
mythread. start ();