Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Followup to previous recursive folder loop - showing thumbnails

Posted on 2006-10-23
7
248 Views
Last Modified: 2010-04-23
Got some help recently (http://www.experts-exchange.com/Q_22027719.html) on displaying thumbnail images on a flowlayoutpanel.  The app should recursively scan through a folder tree laid out like:
\\servername\share\users\username1
\\servername\share\users\username2
\\servername\share\users\username3
[etc...]

Under each of these subfolders sits a file, JPG.LST.

My goal here is to display the images as they are 'read'.  The previous solution scanned all subfolders first, and with over 150,000 images, took a bit too long before the user was presented with anything (about 40 minutes).

Now, I also want to implement a solution (right now, I'm using a menu item) to pause the process, so that the user can continue the following day.  This option would only be available after a full page has been loaded.  I believe I have this implemented already, just thought it might bear mentioning (I'm writing the 'file' and position into an xml config file).

Here's the code as it stands now:

    Private DisplayCount As Integer = 192
    Private NextImage As Integer = 0
    Private UserImagesNames As New ArrayList

 Private Sub process(ByVal strDir As String)
   Dim di As DirectoryInfo = New DirectoryInfo(strDir)
     For Each fi As FileInfo In di.GetFiles("JPG.LST")
      Using sr As New StreamReader(fi.FullName)
       Dim input As String = sr.ReadToEnd()
       UserImagesNames.AddRange(input.Split(CrLf, StringSplitOptions.RemoveEmptyEntries))
       DisplayImages()
      End Using
     Next

     For Each subdir As DirectoryInfo In di.GetDirectories
       process(subdir.FullName)
     Next
    End Sub

   Private Sub DisplayImages()
        If NextImage >= UserImagesNames.Count Then Return

        ' Control type to be place in the FlowLayoutPanel
        Dim pb As PictureBox

        ' Get and dispplay the images
        For idx As Integer = 0 To DisplayCount - 1
            pb = New PictureBox
            pb.SizeMode = PictureBoxSizeMode.AutoSize
            pb.Margin = New System.Windows.Forms.Padding(1, 1, 1, 1)
            pb.Size = New Size(60, 60)
            pb.SizeMode = PictureBoxSizeMode.StretchImage
            pb.Image = Image.FromFile(UserImagesNames(NextImage).ToString)
            pb.Show()
            FlowLayoutPanel1.Controls.Add(pb)
            NextImage += 1
            If NextImage >= UserImagesNames.Count Then Exit For
            Application.DoEvents()
        Next
    End Sub
0
Comment
Question by:sirbounty
  • 4
  • 2
7 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17796667
Hi sirbounty;

I have read through your post but am not sure what questionyou are asking. ;=(

Fernando
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17797412
Well, I believe I have it setup the way I want it - but it doesn't seem to be working 100%.
I dropped the images in half (192 total now) - so that overcomes the out of memory problem, but it's still shutting down here:

pb.Image = Image.FromFile(UserImagesNames(NextImage).ToString)

I get another "out of memory" - but I'm only on NextImage for value 30 - that shouldn't kill it, should it?
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 17797591
I looked at the documentation for the Image.FromFile method and this is what I found.

The method will throw an exception of OutOfMemoryException for the following reasons.

    1. The file does not have a valid image format.
    2. GDI+ does not support the pixel format of the file.

So the exception is misleading.

This is what you may want to do to get around this.

            Try
                pb.Image = Image.FromFile(UserImagesNames(NextImage).ToString)
            Catch ex As Exception
                ' Write the name of the file out to a log file
                Console.WriteLine("Image file not displayed " & UserImagesNames(NextImage).ToString)
            End Try

The documentation may be found at: http://msdn2.microsoft.com/en-us/library/stf701f5.aspx

Fernando
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 67

Author Comment

by:sirbounty
ID: 17798281
Seems to be working.
I think I'll have a default "Cannot load" image to place in there during the catch (cause it leaves a 'blank' box otherwise).

Have a couple more questions following this...stay tuned! :^)
And thanx again!
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17798335
No problem. ;=)
0
 

Expert Comment

by:NimoDos
ID: 20543660
Hi Fernando,

Can an image object hold a pdf document?
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 20545921
Hi NimoDos;

No. You will get the error "OutOfMemoryException" which is misleading. The real reason is that one of two reasons, 1. The file does not have a valid image format or 2. GDI+ does not support the pixel format of the file.

Have a Happy New Year.

Fernando
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question