Results 1 to 10 of 10

Thread: [RESOLVED] Can't delete file "in use by another process" (my own app). HELP!

Threaded View

  1. #1

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    112

    Resolved [RESOLVED] Can't delete file "in use by another process" (my own app). HELP!

    I'm trying to delete a png after displaying it in a ListView.

    But when I try, I get the following error: "The process can not access the file b/c it is being used by another process."

    The only "process" is my own app which just loaded the image. Obviously, I must close or terminate the process so the file can be deleted. Problem is, I didn't create a specific process or Handler to load the image in the first place:

    Code:
                For intCnt = 1 To intTotalNumberOfFiles
                    img = Image.FromFile(strSortedImges(intCnt))
                    ImageList2.Images.Add(img)
                    lsvCollection.SmallImageList = ImageList2               ' Reassign to list with icons.
                    lsvCollection.Items.Add(ParseItemName(strUnsortedNames(intCnt)), intCnt.ToString)
                    img = Nothing
                    ' img.Dispose() doesn't work. Tried adding to fix "File in use" error when deleting file. Causes runtime error.
                Next
    
    ...
    
                FileIO.FileSystem.CopyFile(strSrcPath, strDestPath)
    
    ...
    
                FileIO.FileSystem.DeleteFile(strSrcPath & "file.png") ' Crash occurs here. **************
    I use standard built-in FileIO commands. I DO have some "Using" commands, but none of them are used to load the .png. I can't figure out how to release/dispose/close the process so the PNG can be deleted.

    TIA.

    -------------------------------------
    RESOLVED:

    Trying to Dispose the "img" AFTER it was assigned "nothing" was the problem. Deleting "img = Nothing" stops the "img.Dispose()" from causing a runtime error.
    Last edited by Mugsy323; Oct 15th, 2024 at 08:23 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width