1, the creation of no parameter thread
Thread thread = new Thread (new ThreadStart (Getpic));
Thread. Start ();
private void ShowMessage ()
{
Console.WriteLine ("Hello World");
}
2, with one parameter of the thread
Using Parameterizedthreadstart, the object that contains the data is passed to the thread when the System.Threading.Thread.Start (System.Object) overload method is invoked.
Note that the passed argument can only be type object, but it is possible to force type conversions.
Thread thread = new Thread (new Parameterizedthreadstart (ShowMessage));
String o = "Hello";
Thread. Start ((object) o);
private static void ShowMessage (Object message)
{
String temp = (string) message;
Console.WriteLine (message);
}
3, with two and more parameters of the thread
At this point, the methods and parameters that the thread executes can be encapsulated inside a class, and by instantiating the class, the method can invoke the property to enjoy passing parameters.
For example, you want to pass in two string variables, and then print the output.
public class ThreadTest
{
private string str1;
private string str2;
Public ThreadTest (String A, string b)
{
str1 = A;
str2 = b;
}
public void ThreadProc ()
{
Console.WriteLine (str1 + str2);
}
}
public class Example {public
static void Main ()
{
threadtest tt = new ThreadTest ("Hello", "World");
Thread thread = new Thread (new ThreadStart (TT. ThreadProc));
Thread. Start ();
}
The above is a small set to introduce C # to create a thread with the parameters of the method, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!