1

I want to display a lot of pictures. To do this, all the pictures are full of information. Every time I want to display images of a specific category, I check all the images, each one that has the corresponding label, I'll separate it and show it. It takes a lot of time and the program stops.

What should I do?

IEnumerable<string> AllofItems; 
IEnumerable<string> CurrentofItems;
private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            AllofItems = GetFileList(@"E:\DL\newArtWork\Art").ToArray();
        }

 private void Listbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            foreach (var item in AllofItems)
            {
                var file = ShellFile.FromFilePath(item);
                var auth = file.Properties.System.Author.Value;
                if (listbox.SelectedItem.ToString().Equals(auth))
                   currentList.Add(item);
            }
            CurrentofItems = currentList;

            CurrentofItems.ForEachWithIndex((item, idx) =>
            {
                cover.Items.Add(item);
            });
        }

note:There are about 100 to 300 photos in each category
note:There are 9 thousand files in this place

E:\DL\newArtWork\Art

  • 1
    first step: subdivide the pictures into category subfolders, it'll save a lot of processing time! – Rachel Gallen Jan 31 '19 at 19:30
  • 1
    You may want to convert them into thumbnails, then show the thumbnails due to the total images needed to be shown. Rendering each image is the most intensive operation and unless you change what you show paradigm (less images) the only other option is to show smaller images to achieve a better load time. – ΩmegaMan Jan 31 '19 at 20:03
  • 1
    @RachelGallen What you said was interesting. I do it –  Jan 31 '19 at 20:21
  • @ΩmegaMan yes , I use a thumbnails But the problem is the high number of pictures and reading details –  Jan 31 '19 at 20:22
  • Then you may want to make these processes asynchronous in nature, running in the background and load the data as it comes in. [Asynchronous Programming](https://learn.microsoft.com/en-us/dotnet/csharp/async) – ΩmegaMan Jan 31 '19 at 20:53
  • @ΩmegaMan tnx.. –  Jan 31 '19 at 21:02
  • 1
    You may try something like this: https://stackoverflow.com/a/48892489/1136211 – Clemens Jan 31 '19 at 22:18

1 Answers1

0

It takes a lot of time and the program stops.

Due to the IO intensive nature of the operations, they need to be possibly split up and processed in an asynchronous fashion as to not slow down the IO processing thread as loaded images become available. Meaning you need to put the operation on a separate thread to not block the user's experience with the program.

See Asynchronous programming to get you started on the topic.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122