读书人

关于带参数的线程启动。解决办法

发布时间: 2012-01-13 22:43:29 作者: rapoo

关于带参数的线程启动。
public class TestThread
{
public ucTestScriptTree _tree=new ucTestScriptTree ();
public void ForTest(ucTestScriptTree tn)
{
tn.BeginImport(tn.m_node, tn.list);
}

private void OnShown(object sender, EventArgs e)
{
////1
//Thread m_Thread = new Thread(new ThreadStart(this.ThreadBeginImport));
//m_Thread.Name = "UpImport_Thread";
//m_Thread.Start();

////2
//Thread m_Thread = new Thread(new ParameterizedThreadStart(this.ForTest));
//m_Thread.start(_tree);

////3
ThreadPool.QueueUserWorkItem(new WaitCallback(this.ForTest), _tree);

}
}

分别企图用以上3中方法启动这个带参数的线程,但是都没能成功。直接编译错误

请教各位,这个线程应该怎么才可以启动啊~?~

先谢谢了~

[解决办法]

C# code
//ForTest修改如下:        public void ForTest(object state)        {            ucTestScriptTree tn = (ucTestScriptTree)state;            tn.BeginImport(tn.m_node, tn.list);        } //使用下面的代即可程,亦即主所列之第二方法            Thread m_Thread = new Thread(new ParameterizedThreadStart(ForTest));            m_Thread.Start(_tree);
[解决办法]
public ucTestScriptTree _tree = new ucTestScriptTree();
public void ForTest( object obj )
{
ucTestScriptTree tn = ( ucTestScriptTree )obj;
tn.BeginImport( tn.m_node, tn.list );
}

读书人网 >C#

热点推荐