そうです、これはマルチスレッドへの私の最初のベンチャーなので、私が見逃している信じられないほど単純なものかもしれませんが、ここに行きます...
スレッドプールを使用して、実行時間の短い一連のプロセスを同時に開始します。各プロセスには、fb-tweets-google-plusonesを処理/スクレイプするためのURLが渡さ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);
}
}
ReportProgress:
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);
}
どんな助けでも大歓迎です!