I select Multiple images from file and show their thumbnails in the panel. here is code i write for this::

//files is string type array Containing the image Location
//left, top, picWidth, picHeight are int variables.

           foreach(string file in files)
           {
                   Bitmap bit = new Bitmap(file);
                   ratio = (double)bit.Width / (double)picWidth;
                   PictureBox picBox = new PictureBox();
                   picBox.Name = file;

                   if (left + picWidth > this.Panel2.Width)
                   {
                       left = 10;
                       top += picHeight + 10;
                   }
                 
                   picBox.Size = new Size(picWidth, picHeight);
                  
picBox.Image = bit.GetThumbnailImage(picWidth,(int)((double) bit.Height / ratio), null, System.IntPtr.Zero);
                   picBox.SizeMode = PictureBoxSizeMode.Zoom;
                   
                   picBox.Location = new Point(left, top);
                   this.Panel2.Controls.Add(picBox);
                   picBox.BorderStyle = BorderStyle.FixedSingle;
                   
                   Application.DoEvents();
                   left += picWidth + 10;                          
            }

Sir, My Question is that how can i enhance the speed of my code. Is there any way that i use the treads and it increase the speed of making and showing of thumbnails. or any other way??
i am very thankful to you in advnace..

Yes .. just move the code you have off in to a thread and away you go. You would want to use the thread pool and and feed file names to your thread starter since you have a fixed set of logic to run on each file.

Yes .. just move the code you have off in to a thread and away you go. You would want to use the thread pool and and feed file names to your thread starter since you have a fixed set of logic to run on each file.

Sknake, I have no idea about thread pool. can you give some explanation and give some code snapshoot.

Here is an example application I did that simulates a long database read in another thread while not blocking the main thread. You can use this concept and get 3 threads started that process images while the main thread kicks back and waits for them to wrap up.

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.