Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 586947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:09:35+00:00 2026-05-13T15:09:35+00:00

In my WPF app i need to load some images. I only need to

  • 0

In my WPF app i need to load some images. I only need to display one image at a time. If i load the image when it’s needed, there is a slightly delay. So i thought to myself: “Hey, why not do some preloading in a background thread? Can’t be that hard.” I have some experience with threads, but not enough to know that this thought was wrong. I started programming and run into some problems. I fixed some of the problems and i probably could fix the other problems too, but that would result in spaghetti code. So, I think starting from the scratch would be the best. What initial planing is needed to build a nice and little preloading thread? Is there a pattern or something like that?

Here’s my current setup:

  • LinkedList<string> to stores pathes to the pictures and navigate to the next picture
  • Dictionary<string, BitmapImage> to store the preloaded images
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:09:36+00:00Added an answer on May 13, 2026 at 3:09 pm

    I’d use something like this:

    class ImageManager
    {
      private Dictionary<string, Image> images=
        new Dictionary<string,Image>();
    
      public Image get(string s) {  // blocking call, returns the image
        return load(s);
      }
    
      private Image load(string s) {  // internal, thread-safe helper
        lock(images) {
          if(!images.ContainsKey(s)) {
            Image img=// load the image s
            images.Add(s,img);
            return img; 
          }
          return images[s];
        }
      }
    
      public void preload(params string[] imgs) {  // non-blocking preloading call
        foreach(string img in imgs) { 
          BackgroundWorker bw=new BackgroundWorker();
          bw.DoWork+=(s,e)=>{ load(img); }  // discard the actual image return
          bw.RunWorkerAsync();
        }
      }
    }
    
    // in your main function
    {
       ImageManager im=new ImageManager();
       im.preload("path1", "path2", "path3", "path4"); // non-blocking call
    
       // then you just request images based on their path
       // they'll become available as they are loaded
       // or if you request an image before it's queued to be loaded asynchronously 
       // it will get loaded synchronously instead, thus with priority because it's needed
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need use images in 2 .NET assemblies. One is WPF app {myApp.exe} and
I am developing a WPF app using MVVM and need some help. for the
I need to implement some kind of RBAC for a WPF app that I'm
I need to display some media in a WPF project. The media could be
I need to write a PDF file from my WPF app. I've seen some
I need to pre-fill some form in some web page within my WPF app
I have a WPF app in which I need to programatically manipulate at runtime.
I need to create a command line look-and-feel in a WPF app. In WPF,
My wpf app is eating memory every time the ItemsSource of a TreeView is
In a WPF app, is there a object I can assign to FileSystemWatcher.SynchronizingObject? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.