是的,这是我第一次尝试多线程,所以可能是我想念的非常简单的事情,但是这里......
我正在使用线程池同时启动一堆短时间运行的进程,每个进程都将传递一个 URL 以处理/抓取 fb-tweets-google-plusones 并ReportProgress
通过调用委托将结果返回给我的方法,ThreadDone
但是当线程完成处理后传入已处理的对象时,我不断收到错误Method name expected
但我正在传入方法ReportProgress
?我愿意打赌(希望)这是一件非常简单的事情,更有经验的人可以立即发现。这是我到目前为止所拥有的:
委托定义:
public delegate void ThreadDone(object sender, ScrapeResult scrapedResult);
做工作:
public void DoWork(object sender)
{
while (true)
{
//lock the thread to prevent other threads from processing same job
lock (_threadLock)
{
string url = (string)sender;
result.URL = url;
if (chkFb.Checked)
{
result.Shares = grabber.GetFacebookShares(url);
}
if (chkTwitt.Checked)
{
result.Tweets = grabber.GetTweetCount(url);
}
if (chkPlusOne.Checked)
{
result.PlusOnes = grabber.GetPlusOnes(url);
}
this.Invoke(new ThreadDone(ReportProgress(sender, result))); //ERROR is on this line
}
Thread.Sleep(100);
}
}
报告进度:
private void ReportProgress(object sender, ScrapeResult scrapedResult)//<-- might not need?
{
progressBar.Value++;
ScrapeResult result = (ScrapeResult)sender;//ScrapedResult result = scrapedResult;
outputGrid.Rows.Add(result.URL, result.Shares, result.Tweets, result.PlusOnes);
outputGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
outputGrid.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
}
任何帮助是极大的赞赏!