如何使用ThreadStart创建\启动带有方法参数的线程。
private void GenerateData(Type Method){
ThreadStart tStart = null;
tStart = new ThreadStart(Method);
Thread t = new Thread(tStart);
t.Start();
}
private void DoWork{
//code processing here
}
// I want to call thread like this
private void rundata(){
GenerateData(Dowork);
}
答案 0 :(得分:1)
这听起来像可能只是想要:
private void GenerateData(ThreadStart method)
{
Thread thread = new ThreadStart(method);
thread.Start();
}
你当然可以:
private void DoWork()
{
...
}
private void RunData()
{
GenerateData(DoWork);
}
...虽然考虑到GenerateData
是多么微不足道,但我不确定它真的值得......你可以拥有:
private void RunData()
{
new Thread(DoWork).Start();
}
代替。