BackgroundWorker结果正在被清除

时间:2013-01-28 03:03:52

标签: c# backgroundworker

在我的代码中,我使用后台工作程序来执行任务,并将该任务的返回值设置为DoWorkEventArgs结果。奇怪的是,在DoWork事件期间,Result已设置并包含项目,但是当我在RunWorkerCompleted事件中访问结果时,SOMETIMES结果为空!

        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?

0 个答案:

没有答案