C#线程调用方法时,怎么传参数过去
展开全部
写一个类,把参数封装一下即可。见以下代码
using System;
using System.Threading;
public class MyThreadClass
{
private int x;
public MyThreadClass (int x)
{
this.x = x;
}
public void MyThread()
{
Console.WriteLine("Parameter = {0}", x);
}
}
class Program
{
static void Main(string[] args)
{
MyThreadClass mtc = new MyThreadClass(100);
Thread t = new Thread(mtc.MyThread);
t.IsBackground = true;
t.Start();
Console.ReadKey();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询