private RssForm() { InitializeComponent(); rssWebClient.CachePolicy = new RequestCachePolicy(RequestCacheLevel.CacheIfAvailable); rssWebClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged); rssWebClient.DownloadDataCompleted += new DownloadDataCompletedEventHandler(webClient_DownloadRssCompleted); imageWebClient.CachePolicy = new RequestCachePolicy(RequestCacheLevel.CacheIfAvailable); imageWebClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged); imageWebClient.DownloadDataCompleted += new DownloadDataCompletedEventHandler(webClient_DownloadImageCompleted); rssFeedsListView.Items.Clear(); foreach (KeyValuePair <string, string> s in Program.Settings.RssFeeds) { rssFeedsListView.Items.Add(new RssListViewItem(s.Key, s.Value)); } lvwColumnSorter.SortColumn = 3; rssItemsListView.ListViewItemSorter = lvwColumnSorter; foreach (RssListViewItem r in rssFeedsListView.Items) { Image i = null; try { using (IsolatedStorageFileStream iStream = new IsolatedStorageFileStream(Toolbox.MD5(r.Name), FileMode.Open, isoStore)) { Image img = new Bitmap(iStream); i = new Bitmap(img); img.Dispose(); } } catch { } if (i != null) { FeedImageList.Images.Add(r.Name, i); } } }
void webClient_DownloadImageCompleted(object sender, DownloadDataCompletedEventArgs e) { if (!e.Cancelled) { if (e.Error == null) { RssListViewItem r = e.UserState as RssListViewItem; try { Image i = byteArrayToImage(e.Result); FeedImageList.Images.Add(r.Name, i); try { using (IsolatedStorageFileStream oStream = new IsolatedStorageFileStream(Toolbox.MD5(r.Name), FileMode.Create, isoStore)) { i.Save(oStream, ImageFormat.Png); } } catch { } } catch (Exception ee) { HandleException(ee); } } } }