i made a web service that returns the name of the images in a file and returns the array of string with the file name with its folder name attached to it i.e. "pictures/image1.jpg".
the client takes the url and adds it to the string i.e "http://localhost:3323/pictures/image1.jpg".

The images is then loaded on the scrollpanel using this code ...

void service_getimagesCompleted(object sender, ServiceReference1.getimagesCompletedEventArgs e)
        {
            string url = "http://localhost:3323";
            string[] files = e.Result.ToArray();
            
           
            foreach (string file in files)
            {
                try
                {
                    System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
                    bi.UriSource = new Uri(url + "/" + file);
                    
                    Image i = new Image();
                    i.Height = scrollViewer1.Height;
                    i.Width = scrollViewer1.Height;
                    i.Margin = new Thickness(8);
                    i.Source = bi;
                    
                    stackPanel1.Children.Add(i);
                }
                catch { }
            }
            scrollViewer1.UpdateLayout();

But when i execute this...the web browser loads up...and becomes extremely heavy and only loads like 12 images out of 30.
i dont want it to become heavy i.e. allow the web browser to be smooth while the images are loading...

i also want to know why its only loading some of it..and not all of the images...

thank you and waiting for reply!.....

Dani AI

Generated

Short diagnosis and practical plan.

@ICode’s approach creates Image elements for every file in a StackPanel inside a ScrollViewer, so the plugin tries to download/decoding all images at once. That allocates lots of UI elements and work up front; switching to a data-bound ItemsControl/ListBox that uses a virtualizing items host avoids creating off-screen visuals and fixes the “everything loads at once -> browser chokes” symptom. (learn.microsoft.com)

Why it’s slow and why some images don’t appear. Decoding bitmaps is CPU- and memory-heavy, and desktop Silverlight does not provide a background-decode option (the BackgroundCreation flag that performs background decode is only available on Windows Phone). Also desktop Silverlight does not expose WPF-style DecodePixelWidth/Height, so the easiest, lowest-cost fix is to serve true thumbnails (smaller files) instead of asking the client to downscale lots of huge images. These constraints explain why many images can stall or fail when added all at once. (learn.microsoft.com)

Concrete next steps (practical, copy-paste-able)

  • Stop adding all images to a ScrollViewer/StackPanel. Use a ListBox/ItemsControl with an ItemTemplate and let the framework virtualize the item containers.
  • Produce server-side thumbnails (or pre-resized images) so each image is small to transfer and decode.
  • Use WebClient.OpenReadAsync (or OpenReadCompleted) and limit concurrent downloads to a small number (3–4). This avoids saturating browser connections and reduces simultaneous decode work. Browsers also limit parallel connections per host, so throttling helps overall throughput. (learn.microsoft.com)

Example throttling pattern (Silverlight C#):

Queue<Uri> queue = new Queue<Uri>();
int running = 0;
const int MAX = 3;

void Enqueue(Uri u) { queue.Enqueue(u); TryStart(); }

void TryStart()
{
  while (running < MAX && queue.Count > 0)
  {
    var uri = queue.Dequeue();
    var wc = new WebClient();
    running++;
    wc.OpenReadCompleted += (s,e) =>
    {
      running--;
      if (e.Error == null && !e.Cancelled)
      {
        var bi = new BitmapImage();
        bi.SetSource(e.Result);            // decode (may block briefly)
        Dispatcher.BeginInvoke(() => {
          var img = new Image { Source = bi, Width = 120, Height = 120 };
          itemsPanel.Children.Add(img);    // or add to virtualized list source
        });
      }
      else { /* log e.Error */ }
      TryStart();
    };
    wc.OpenReadAsync(uri);
  }
}

Quick troubleshooting checklist: remove empty catch blocks (they hide why images fail), log OpenReadCompleted.e.Error and BitmapImage ImageFailed/ImageOpened events, clear Image.Source for items scrolled out of view, and prefer thumbnails + virtualization. This follows ’s WebClient idea but adds concurrency control and virtualization to keep the browser responsive.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.