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 8521191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:45:03+00:00 2026-06-11T06:45:03+00:00

I’m currently trying to create a FileViewer control, and after I’ve added Items (Filenames

  • 0

I’m currently trying to create a FileViewer control, and after I’ve added Items (Filenames with Icons, size, etc) to my ListView (Icon – Filename – Extension – Size) I also check if the file is an image (png/jpg, etc) but this I do on a different Thread.

My expectation of a thread is that it runs beside the main application, but after I’ve added all my files I start this thread. It checks all files in the ListView and creates thumbnails for them. If done correctly, ListView icons should appear one after one as they’re loaded – but they’re not. They all appear at the same time.

…and I can’t do anything while the Thread is active.

Why is this happening and what am I doing wrong? I’ve dealt with Threads before and it’s always worked, I invoke the method with a Callback.

Flow of the Thread:

  1. Format file key = “C:\image.png” = “C_image_png”.
  2. Check if thumbnail to image exists (by checking it’s key), then use it
  3. Else load thumbnail with Image.FromFile().GetThumbnailImage() and add image with Key to Listview’s images
  4. Finally change the ImageKey of the ListView item.

All done in a thread.

private void GetFiles()
{
   // Load all files in directory

   Thread t = new Thread(new ThreadStart(GetImageFiles));
   t.Priority = ThreadPriority.Lowest;
   t.Start();

}

delegate void GetImageFilesCallback();

    private void GetImageFiles()
    {
        if (this.IsHandleCreated)
        {
            if (files.InvokeRequired)
            {
                GetImageFilesCallback callback = new GetImageFilesCallback(GetImageFiles);
                this.Invoke(callback);
            }
            else
            {
                string extension = "";
                string key = "";

                foreach (string file in _files)
                {
                    extension = FileManager.GetExtension(file);
                    key = (DirectoryCurrent + file).Replace(":", "").Replace("\\", "_").Replace(".", "_");

                    foreach (string knownimages in _knownImageTypes)
                    {
                        if (extension.ToLower() == knownimages)
                        {
                            foreach (ListViewItem item in files.Items)
                            {
                                if (item.Text == file)
                                {
                                    if (files.SmallImageList != null)
                                    {
                                        if (files.SmallImageList.Images[key] == null)
                                        {
                                            files.SmallImageList.Images.Add(key, Image.FromFile(DirectoryCurrent + file).GetThumbnailImage(16, 16, null, IntPtr.Zero));
                                            files.LargeImageList.Images.Add(key, Image.FromFile(DirectoryCurrent + file).GetThumbnailImage(32, 32, null, IntPtr.Zero));
                                        }

                                        files.Items[item.Index].ImageKey = key;
                                    }
                                }
                            }
                        }
                    }
                }

                files.Refresh();
            }
        }
    }
  • 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-06-11T06:45:04+00:00Added an answer on June 11, 2026 at 6:45 am

    The method that your thread calls is invoking itself onto the main thread, and then doing all the work in that thread, thereby blocking your UI.

    You should arrange your code so that the thread code does not touch the ListView, but just loads each image, then invokes a main-thread method, passing the bitmaps so that the main thread can assign them to the ListView.

    Here’s a sketch of what I mean:

    // this is your thread method
    // it touches no UI elements, just loads files and passes them to the main thread
    private void LoadFiles(List<string> filenames) {
       foreach (var file in filenames) {
          var key = filename.Replace(...);
          var largeBmp = Image.FromFile(...);
          var smallBmp = Image.FromFile(...);
          this.Invoke(new AddImagesDelegate(AddImages), key, largeBmp, smallBmp);
       }
    }
    
    // this executes on the main (UI) thread    
    private void AddImages(string key, Bitmap large, Bitmap small) {
       // add bitmaps to listview
       files.SmallImageList.Images.Add(key, small);
       files.LargeImageList.Images.Add(key, large);
    }
    
    private delegate AddImagesDelegate(string key, Bitmap large, Bitmap small);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.