private void HandleModuleDownloaded(DownloadCompletedEventArgs e) { string uri = (string)e.UserState; List <ModuleInfo> moduleInfos = this.GetDownloadingModules(uri); Exception error = e.Error; if (error == null) { try { if (e.Result == null) { throw new Exception("ModuleDownloaded Failed"); } //记录已经下载的模块 this.RecordDownloadComplete(uri); Debug.Assert(!e.Cancelled, "Download should not be cancelled"); XapAnalysis analysis = new XapAnalysis(); analysis.Analysis(e.Result); this.RecordDownloadSuccess(uri); SaveLocalXapFile(e.Result, moduleInfos[0]); Debug.WriteLine("Load Xap From WCF : " + moduleInfos[0].FileName); } catch (Exception ex) { error = ex; } finally { if (e.Result != null) { e.Result.Close(); } } } foreach (ModuleInfo moduleInfo in moduleInfos) { this.RaiseLoadModuleCompleted(moduleInfo, error); } }
private void IFileDownloader_DownloadCompleted(object sender, DownloadCompletedEventArgs e) { // A new IFileDownloader instance is created for each download. // I unregister the event to allow for garbage collection. IFileDownloader fileDownloader = (IFileDownloader)sender; fileDownloader.DownloadProgressChanged -= this.IFileDownloader_DownloadProgressChanged; fileDownloader.DownloadCompleted -= this.IFileDownloader_DownloadCompleted; // I ensure the download completed is on the UI thread so that types can be loaded into the application domain. //确保下载完成处理是在UI线程中,这样便于类型加载到应用程序中。 if (!Deployment.Current.Dispatcher.CheckAccess()) { Deployment.Current.Dispatcher.BeginInvoke(new Action <DownloadCompletedEventArgs>(this.HandleModuleDownloaded), e); } else { this.HandleModuleDownloaded(e); } }
private void HandleModuleDownloaded(DownloadCompletedEventArgs e) { string uri = (string)e.UserState; List<ModuleInfo> moduleInfos = this.GetDownloadingModules(uri); Exception error = e.Error; if (error == null) { try { if (e.Result == null) throw new Exception("ModuleDownloaded Failed"); //记录已经下载的模块 this.RecordDownloadComplete(uri); Debug.Assert(!e.Cancelled, "Download should not be cancelled"); XapAnalysis analysis = new XapAnalysis(); analysis.Analysis(e.Result); this.RecordDownloadSuccess(uri); SaveLocalXapFile(e.Result, moduleInfos[0]); Debug.WriteLine("Load Xap From WCF : " + moduleInfos[0].FileName); } catch (Exception ex) { error = ex; } finally { if (e.Result != null) e.Result.Close(); } } foreach (ModuleInfo moduleInfo in moduleInfos) { this.RaiseLoadModuleCompleted(moduleInfo, error); } }
private void IFileDownloader_DownloadCompleted(object sender, DownloadCompletedEventArgs e) { // A new IFileDownloader instance is created for each download. // I unregister the event to allow for garbage collection. IFileDownloader fileDownloader = (IFileDownloader)sender; fileDownloader.DownloadProgressChanged -= this.IFileDownloader_DownloadProgressChanged; fileDownloader.DownloadCompleted -= this.IFileDownloader_DownloadCompleted; // I ensure the download completed is on the UI thread so that types can be loaded into the application domain. //确保下载完成处理是在UI线程中,这样便于类型加载到应用程序中。 if (!Deployment.Current.Dispatcher.CheckAccess()) { Deployment.Current.Dispatcher.BeginInvoke(new Action<DownloadCompletedEventArgs>(this.HandleModuleDownloaded), e); } else { this.HandleModuleDownloaded(e); } }