public void printExercices() { RScache cache = new RScache(); foreach (RSapiExercice apiEx in apiExercices) { RSexercice exercice = new RSexercice(apiEx); RSapiResource thumbnailRes = exercice.getThumbnailResource(); if (thumbnailRes != null) { string thumbnailLocalPath = cache.getLocalPathForURL(thumbnailRes.url, thumbnailRes.name); if (thumbnailLocalPath == null) { thumbnailLocalPath = cache.downloadThumbnailAsync(thumbnailRes); } exercice.ThumbnailLocalPath = thumbnailLocalPath; } Application.Current.Dispatcher.BeginInvoke(new Action(() => this.exercices.Add(exercice))); } }
// Demande de téléchargement d'une image public string downloadThumbnailAsync(RSapiResource thumbnail) { string thumbnailLocalPath = Path.Combine(specificFolder, thumbnail.name); using (WebClient wbClient = new WebClient()) { Uri ur = new Uri(thumbnail.url); while (true) { try { wbClient.DownloadFileAsync(ur, thumbnailLocalPath); Task.Delay(2500).Wait(); break; } catch (Exception e) { MessageBox.Show(e.Message); } } } return(thumbnailLocalPath); }