一、带一个参数
Thread thrd = new Thread (new ParameterizedThreadStart(StartWriteToText));
thrd.Start (strParameter);
static void StartWriteToText(object objParameter)
{
// ....
}
private static void StartThreadWriteToText(object objParameter)
{
ThreadParameter thrdParameter = (ThreadParameter)objParameter;
}
二、带多个参数(方法一)
struct ThreadParameter
{
public string strFilePath;
public string strSqlScript;
};
ThreadParameter thrdParameter = new ThreadParameter();
thrdParameter.strFilePath = "";
thrdParameter.strSqlScript = "";
Thread thrd = new Thread (new ParameterizedThreadStart(StartWriteToText));
thrd.Start (thrdParameter);
private static void StartThreadWriteToText(object objParameter)
{
ThreadParameter thrdParameter = (ThreadParameter)objParameter;
//......
}
三、带多个参数(方法二)
class ParameterClass
{
public string strFilePath;
public string strSqlScript;
public void StartWriteToText()
{
//......
}
}
ParameterClass pmterClass = new ParameterClass();
pmterClass.strFilePath = "";
pmterClass.strSqlScript = "";
Thread thrd = new Thread(new ThreadStart(pmterClass.StartWriteToText));thrd.Start();