Excessive Image Resource


So I'm writing a program to clear old images out of some folders. I get the old and new folder
paths from XML and then check each image against my database then I move it using MoveFile()
if it meets my requirements. The one folder I'm checking contains 46,600 images (jpegs, gifs, tifs, bmps and pngs)
with my biggest image being 127 KB.
Now the program runs perfectly and does exactly what it's suppose to however my server resources in this case
were at 95 - 100% the entire time. It also took more than 10hrs to run. Please let me know how I can overcome this.
I need to reduce the system resource usage dramatically. I can't move any images out of the folder and it
has to be done in VB.Net and the images can't be deleted also I have to check all the fields in the SQL. This is my code

Dim value As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
            Dim info As System.IO.FileInfo
            Dim dr As SqlDataReader
            Dim cmd As SqlCommand
            Dim sql As String = ""

            connections = XDocument.Load("connect.xml")

            Dim pathValues = From c In connections.<Connect>.<section> Where c.Attribute("id").Value = "facilities" Select c.<path>.Value, c.<netPath>.Value

            ' Set the file from which the files will be manipulated and moved from
            Dim sourcepath As String = pathValues.ElementAt(0).path
            Dim newPath As String = pathValues.ElementAt(0).netPath

            value = My.Computer.FileSystem.GetFiles(sourcepath, FileIO.SearchOption.SearchTopLevelOnly, "*.*")

            'Loop thru the files retrieved from the source folder
            For Each foundFile As String In value
                info = My.Computer.FileSystem.GetFileInfo(foundFile)
                Dim fileName As String = info.Name
                sql = "SELECT MemCat.Pic1, MemCat.Pic2, MemCat.Pic3, MemCat.Pic4, MemCat.Pic5, tempMemCat.Pic1, " +
                        "tempMemCat.Pic2, tempMemCat.Pic3, tempMemCat.Pic4, tempMemCat.Pic5 " +
                        "FROM MemCat FULL OUTER JOIN tempMemCat ON MemCat.MemberID = tempMemCat.MemberID " +
                        "WHERE MemCat.Pic1 = '" + fileName + "' OR MemCat.Pic2 = '" + fileName + "' OR MemCat.Pic3 = '" + fileName + "' OR MemCat.Pic4 = '" + fileName + "' OR " +
                        "MemCat.Pic5 = '" + fileName + "' OR tempMemCat.Pic1 = '" + fileName + "' OR tempMemCat.Pic2 = '" + fileName + "' OR tempMemCat.Pic3 = '" + fileName + "' OR " +
                        "tempMemCat.Pic4 = '" + fileName + "' OR tempMemCat.Pic5 = '" + fileName + "'"
                SQLS = sql

                cmd = New SqlCommand(sql, connSO)
                dr = cmd.ExecuteReader()

                If dr.HasRows = False Then
                    My.Computer.FileSystem.MoveFile(info.ToString(), newPath + fileName, True)
                End If


It will take the resource as number of files increses everytime. You should find some mechanisim to freeup the resource like using the background worker or threading. What if the file count reaches lacks?.. Cant u take out the old files after comparing to backup folder?

This article has been dead for over six months. Start a new discussion instead.