5 Replies - 1227 Views - Last Post: 11 October 2012 - 04:10 PM Rate Topic: -----

#1 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 73
  • View blog
  • Posts: 922
  • Joined: 09-May 09

Handle on files

Posted 09 October 2012 - 08:02 AM

Hi guys,

I have 2 images that both have a handle on them so in my project im downloading a new version of the image (http web request) but an error is caught.

I cannot for the life of me find where is issue occurs, i had this issue before surrounding deleting the image which was resolved by replacing image.fromFile with picturebox.load

I have tried disposing of the image before overwriting it but it doesnt work
frontCover.image.dispose()

Does anyone have any idea where else an image could be held in memory

Kevin

Is This A Good Question/Topic? 0
  • +

Replies To: Handle on files

#2 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,478
  • Joined: 16-March 11

Re: Handle on files

Posted 09 October 2012 - 08:44 AM

Place a breakpoint, and go through the code line by line with f11, mouse over all your variables as you do so making sure they are the correct values they need to be. Let us know if you find any specific errors, then we can help you out. Other than that though, it's your ride to take here. :)
Was This Post Helpful? 0
  • +
  • -

#3 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1030
  • View blog
  • Posts: 4,008
  • Joined: 02-July 08

Re: Handle on files

Posted 09 October 2012 - 09:48 AM

Show some code.
Was This Post Helpful? 0
  • +
  • -

#4 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 73
  • View blog
  • Posts: 922
  • Joined: 09-May 09

Re: Handle on files

Posted 11 October 2012 - 12:41 PM

Sry for the delay

load posters on window
 Me.Cursor = Cursors.WaitCursor

        Dim s As String
        For Each s In System.IO.Directory.GetFiles("C:\Program Files (x86)\myMovie Manager v3.01\Posters\")
            ' System.IO.File.Delete(s)
            Kill(s)
        Next s

        Try

            'get integer value of selected movie
            Dim i = ListView20.Items.Item(ListView20.SelectedIndices(0)).Index


            'Get Movie Name from selection
            Dim movieName = ListView20.Items.Item(ListView20.SelectedIndices(0)).Text
            Dim directory = directorylist.Item(i)

            'get images 
            PosterViewer2.fetchImages(directory, "\MetaData\movieData.xml", sender, e)

            'dont download same images
            posterIndex = i
        Catch ex As Exception

        End Try

        Try
            'change HD poster image
            frontCoverPicturebox.Image.Dispose()
            frontCoverPicturebox.Load(directorylist.Item(posterIndex) + "\folderHD.jpg")


            'Change poster image in carousel
            Dim selectedButton As RadButtonElement
            selectedButton = CType(RadCarousel2.SelectedItem, RadButtonElement)
            selectedButton.Image = Image.FromFile(directorylist.Item(posterIndex) + "\folder.jpg")
            RadCarousel2.Update()

        Catch ex As Exception

        End Try


        'change cusor look
        Me.Cursor = Cursors.Arrow



user clicks poster and downloads file
  'FilePath
        Dim fileName As String = String.Concat(directoryName, xmlFileName)

        'Get the movie name
        Dim movieTitle() As String
        movieTitle = directoryName.split("\")



        If File.Exists(fileName) Then

            'New document
            Dim doc As XDocument


            Try

                'load file into document
                doc = Xdocument.Load(fileName)

                'Query for poster data
                Dim moviePoster = From p In doc.Descendants("image")
                                  Where p.Attribute("type") = "poster" And p.Attribute("size") = "original"
                                  Select posterURL = p.Attribute("url").Value.ToString


     

                Try
                    Form1.frontCoverPicturebox.Image.Dispose()


                    Dim temp As String = Form1.directorylist(i) + "\folderHD" ' String.Concat("C:\Program Files (x86)\myMovie Manager 3.01\data\Poster Images\folderHD", i)
                    Dim coverFilePath = String.Concat(temp, ".jpg")

                    Dim webClient As New System.Net.WebClient

                    webClient.DownloadFile(moviePoster(4).ToString, coverFilePath)
                    webClient.Dispose()


                Catch ex As Exception


                End Try


            Catch ex As Exception

            End Try
        End If



Thanks for any help
Was This Post Helpful? 0
  • +
  • -

#5 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 73
  • View blog
  • Posts: 922
  • Joined: 09-May 09

Re: Handle on files

Posted 11 October 2012 - 03:55 PM

Hi Guys the problems seem to lay with this function

function purpose:
parse file for image urls
download into a folder location in c:
i add images to a picturebox array
add pictureboxes to form with images loaded from file

i believe the picturebox array is where the problem is.
  Dim i As Integer = 0

        'FilePath
        Dim fileName As String = String.Concat(directoryName, xmlFileName)

        'Get the movie name
        Dim movieTitle() As String
        movieTitle = directoryName.Split("\")


        If File.Exists(fileName) Then

            'New document
            Dim doc As XDocument


            Try

                'load file into document
                doc = Xdocument.Load(fileName)

                'Query for poster data
                Dim moviePoster = From p In doc.Descendants("image")
                                  Where p.Attribute("type") = "poster" And p.Attribute("size") = "thumb"
                                  Select posterURL = p.Attribute("url").Value.ToString



                'download posters and put in temp location
                While i <= moviePoster.Count

                    Try

                        'Download poster
                        Dim temp As String = String.Concat("C:\Program Files (x86)\myMovie Manager v3.01\Posters\folder", i)
                        Dim coverFilePath = String.Concat(temp, ".jpg")
                        Dim webClient As New System.Net.WebClient
                        webClient.DownloadFile(moviePoster(i).ToString, coverFilePath)
                        webClient.Dispose()

                        i = i + 1
                    Catch ex As Exception

                        i = i + 1
                    End Try

                End While

            Catch ex As Exception

            End Try
        End If


        'Get total number of posters in directory
        Dim di As New IO.DirectoryInfo("C:\Program Files (x86)\myMovie Manager v3.01\Posters")
        Dim aryFi As IO.FileInfo() = di.GetFiles("*.jpg")



        'x position
        Dim xPos As Integer = 10

        'Create array for pictureboxes 
        ReDim PB(aryFi.Count)


        Dim k As Integer = 0
        While k <= aryFi.Count - 1


            'assign picturebox to array in correct position with name
            PB(k) = New PictureBox
            PB(k).Name = k

            'try and load image from file 
            Try

                Dim path = "C:\Program Files (x86)\myMovie Manager v3.01\Posters" + "\folder" + k.ToString + ".jpg"
                If File.Exists(path) Then
                    PB(k).Load(path)
                End If

            Catch ex As Exception

            End Try

            'position of the picturebox 
            PB(k).Location = New System.Drawing.Point(xPos, 10)

            PB(k).Size = New Size(92, 138)
            PB(k).SizeMode = PictureBoxSizeMode.StretchImage
            PB(k).BorderStyle = 1

            'Add control to panel 1
            Panel1.Controls.Add(PB(k))



            '  Wire this control up to an appropriate event handler
            AddHandler PB(k).Click, AddressOf posterPicClicked

            xPos = xPos + 97

            k = k + 1
        End While

        Me.ShowDialog()
        Me.BringToFront()


Was This Post Helpful? 0
  • +
  • -

#6 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 73
  • View blog
  • Posts: 922
  • Joined: 09-May 09

Re: Handle on files

Posted 11 October 2012 - 04:10 PM

SOLVED . . ..

handle was held on the picturebox array, dispose of pictureboxes in array

Dim P As Integer = 0
                While P < PB.Length - 1
                    PB(P).Dispose()
                    P = P + 1
                End While




thanks to all who looked.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1