C# 多线程无参/带参执行方法

private void button1_Click(object sender, EventArgs e)
{
	//无参方式一
	Thread thread = new Thread(display);
	thread.Start();
	
	//无参方式二
	Thread thread = new Thread(new ThreadStart(display));
	thread.Start();
	
	//带参方式一
	Thread thread = new Thread(display);
	thread.Start("Name");
	
	//带参方式二
	Thread thread = new Thread(new ThreadStart(delegate () { display("Name", age); }));
	thread.Start();
}

public void display()
{
	//这里是执行的代码
}

public void display(object Name)
{
	//这里是执行的代码
}

public void display(string Name,int age)
{
	//这里是执行的代码
}

 

点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注