I have developed an application that loaded many images in a listview using ImageList in c# .net framework 4. The images are also compressed. When many many images are loaded and compressed then it takes a long time. So I call the method in backgroundworker. In the backgroundworker I had to add images to ImageList and add ImageList to ListView. So I have used safeinvoke() method listView1.SafeInvoke(d=>d.Items.Add(item)).
Everything works fine. Images are displayed one by one in the listview.
But the release of the application doesn’t work properly in some pc and properly works in some other pc. Doesn’t work properly means, If 100 images are browsed using OpenFileDialog to load then some images are loaded and added to listview and then the loading is automatically stopped without adding all images to the listview and no exception shows.

I have spent many times to solve this problem but couldn’t figure out the problem. . Where is the problem? Can anybody help me?

private void bgwLoading_DoWork(object sender, DoWorkEventArgs e)
            ArrayList a = (ArrayList)e.Argument;
            string[] fileNames = (string[])a[0];
private void loadMultiImages(string[] fileNames)        
            int i = 1;
            int totalFiles = fileNames.Count();
                foreach (string flName in fileNames)
                    if (!flName.Contains("Thumbs.db"))
                            Bitmap newBtmap = (Bitmap)Image.FromFile(flName);
                            FileInfo fi = new FileInfo(flName);
                            long l = fi.Length;
                            if (l > compressSize)
                                    newBtmap = resizeImage(newBtmap, 1024,768) ;
                                    newBtmap = saveJpeg(IMAGE_PATH + (SCANNING_NUMBER +  
                                    ) + ".jpg", newBtmap, IMAGE_QUALITY);
                                File.Copy(flName, TEMP_IMAGE_PATH + (SCANNING_NUMBER + 1) + ".jpg");

                            if (!bgwLoading.CancellationPending)
                                this.SafeInvoke(d => d.addItemToLvImageContainer(newBtmap));
                                bgwLoading.ReportProgress((int)Math.Round((double)i / (double)(totalFiles) * 100));
        public void addItemToLvImageContainer(Bitmap newBtmap)
            ListViewItem item;
            item = new ListViewItem();
            item.ImageIndex = SCANNING_NUMBER - 1;
            item.Text = SCANNING_NUMBER.ToString();
            lvImageContainer.Items[item.ImageIndex].Focused = true;

Did you use saveJpeg(IMAGE_PATH + (SCANNING_NUMBER in one place and File.Copy(flName, TEMP_IMAGE_PATH + (SCANNING_NUMBER

If not both paths are the same, from wich one do you show the images?

Hope this helps

Be a part of the DaniWeb community

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