引用命名空间:using System.Threading;
一、调用无参函数
Thread th = new Thread(new ThreadStart(Function));
th.Start();
private static void Function()
{
//被线程调用的方法
}
二、调用有一个参数的函数
Thread th = new Thread(new ParameterizedThreadStart(Function));
th.Start("需要传递的参数");
private static void Function(object obj)
{
//被线程调用的方法
}
三、调用有多个参数的函数
MyClass m = new MyClass();
m.name = "佚玥";
m.age =24;
Thread th = new Thread(new ThreadStart(m.Function));
th.Start();
//自己定义的参数传递类
class MyClass
{
public string name;
public int age;
//自己需要的参数 都 设置 成 字段 或属性
public void Function()
{
//被线程调用的方法
}
}
一、调用无参函数
Thread th = new Thread(new ThreadStart(Function));
th.Start();
private static void Function()
{
//被线程调用的方法
}
二、调用有一个参数的函数
Thread th = new Thread(new ParameterizedThreadStart(Function));
th.Start("需要传递的参数");
private static void Function(object obj)
{
//被线程调用的方法
}
三、调用有多个参数的函数
MyClass m = new MyClass();
m.name = "佚玥";
m.age =24;
Thread th = new Thread(new ThreadStart(m.Function));
th.Start();
//自己定义的参数传递类
class MyClass
{
public string name;
public int age;
//自己需要的参数 都 设置 成 字段 或属性
public void Function()
{
//被线程调用的方法
}
}