110,536
社区成员
发帖
与我相关
我的任务
分享
class Program
{
static void Main(string[] args)
{
Hashtable tb=new Hashtable();
ParameterizedThreadStart tStart = new ParameterizedThreadStart(Calculate);
Thread thread = new Thread(tStart);
thread.Start(tb);//传递参数
Thread.Sleep(2000);
Console.Read();
}
public static void Calculate(ref Hashtable arg)
{
//处理该HashTable
}
}
var x = 1;
ThreadPool.QueueUserWorkItem(h =>
{
x++;
Console.WriteLine(x);
Calculate(x);
});
这里也还是随便写你的代码,不用管什么“参数签名问题”。var x = 1;
var t = new Thread(() =>
{
x ++;
Console.WriteLine(x);
Calculate((x);
});
t.Start();
完全不用顾忌什么“参数签名问题”。Calculate(ref tb);
啊?!我不过就是用 Calculate(x); 来举例嘛。我都比较明确地说了“你可以调用任何代码”喽。public static void Calculate2(Hashtable arg)
{
Calculate(ref arg);
}