在我的代码中,我使用后台工作人员执行任务,并将该任务的返回值设置为 DoWorkEventArgs Result。奇怪的是,在 DoWork 事件期间,设置了 Result 并包含项目,但是当我在 RunWorkerCompleted 事件中访问结果时,有时 Result 是空的!
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
var i = YouTubeDownloader.GetYouTubeVideoUrls(videoUrls);
e.Result = i; //Contains items
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
UseWaitCursor = false;
if (e.Error != null)
throw e.Error;
List<YouTubeVideoQuality> urls = e.Result as List<YouTubeVideoQuality>; // Empty?