メソッドでバックグラウンドワーカーを定義できますか?
private void DownLoadFile(string fileLocation){
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler((obj, args) => {
// Will be executed by back ground thread asynchronously.
args.Result = Download(fileLocation);
});
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler((obj, args) => {
// will be executed in the main thread.
Result r = args.Result as Result;
ReportResult(r);
});
worker.RunWorkerAsync(fileLocation);
}
質問:Download()関数がファイルのダウンロードに長い時間がかかる場合、RunWorkerCompleted()が実行される前にGCが起動してワーカーオブジェクトを収集できますか?