System.IO.IOException was unhandled Message: An unhandled exception of type 'System.IO.IOException' occurred in PresentationCore.dll Additional information: Unable to read data from stream.
The error appears irregularly, sporadically. The algorithm is as follows:
- I collect links to pictures on the Internet, with this everything is OK
- for display I use
ListBoxwhich is connected with theObservableCollection<BitmapImage>collectionObservableCollection<BitmapImage>
Here is the method that fills the collection.
/// <summary> /// ΠΠ°ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ ΡΠΏΠΈΡΠΊΠ° ΠΊΠ°ΡΡΠΈΠ½ΠΎΠΊ /// </summary> /// <param name="addresses"></param> private void LoadListImages(List<string> addresses) { //Π±ΡΠ΄ΡΡΠ°Ρ ΠΊΠΎΠ»Π»Π΅ΠΊΡΠΈΡ ΠΊΠ°ΡΡΠΈΠ½ΠΎΠΊ ListImages = new ObservableCollection<BitmapImage>(); //to UI MessageUser.MessageJob.Report("ΠΠ°Π³ΡΡΠΆΠ°Π΅ΠΌ ΠΊΠ°ΡΡΠΈΠ½ΠΊΠΈ..."); try { int i = 1; BitmapImage bImage = null; foreach (var address in addresses) { //to UI MessageUser.MessageJob.Report($"ΠΠ°Π³ΡΡΠΆΠ°Π΅ΠΌ {i}..."); //Π½ΠΎΠ²Π°Ρ ΠΊΠ°ΡΡΠΈΠ½ΠΊΠ° bImage = new BitmapImage(new Uri(address, UriKind.RelativeOrAbsolute)); //ΡΠ°Π·ΠΌΠ΅ΡΡ bImage.DecodePixelHeight = 100; bImage.DecodePixelWidth = 100; //ΠΊΠ°ΡΡΠΈΠ½ΠΊΡ Π² ΠΊΠΎΠ»Π»Π΅ΠΊΡΠΈΡ ListImages.Add(bImage); //ΡΡΠ΅ΡΡΠΈΠΊ i++; } } catch (Exception ex) { Debug.WriteLine($"{nameof(LoadListImages)} - {ex.Message}"); throw; } } The method works out with a bang. I even walked through the steps, and even in situations where this error occurs, but the error occurs immediately after exiting the method, that is, as I understand it, at the moment when the UI should start displaying pictures and BitmapImage starts to load on the desired link. How can this be overcome?
ListImages = new ObservableCollection<BitmapImage>();- Bulson