我試圖循環通過一個XmlNodeList,從中獲取一些數據,然後啓動一個使用這塊數據的新線程。循環通過XmlNodeList然後啓動每個新線程
這是我到目前爲止有:
public void startRun(string kwd)
{
doRun run = new doRun();
run.run(kwd);
}
private void startBtn_Click(object sender, EventArgs e)
{
XmlDocument searches = new XmlDocument();
searches.Load("data\\Searches.xml");
XmlNodeList search = searches.SelectNodes("Searches/search");
var nodeCount = search.Count;
for(var i = 0; i < nodeCount; i++)
{
string kwd = System.Uri.EscapeDataString(search[i].SelectSingleNode("query").InnerText);
doRun run = new doRun(this);
Thread newThread = new Thread(new ThreadStart(startRun(kwd)));
}
}
這是不工作的。 Visual Studio是說Method name expected
這條線:
Thread newThread = new Thread(new ThreadStart(startRun(kwd)));
如何傳遞這個參數到新THEAD?
' Thread newThread = new Thread(new ParameterizedThreadStart(startRun),kwd);'給我這個錯誤:''System.Threading.Thread.Thread(System.Threading.ParameterizedThreadStart,int)'的最佳重載方法匹配'有一些無效參數' – 2013-03-14 19:04:19
您是否還修改'startRun',正如我所提及的? 'startRun'必須帶一個** **對象**參數! – 2013-03-14 19:07:02
是的,我修改了startRun到'startRun(object kwdObject)' – 2013-03-14 19:08:04