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:
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.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. **************
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.




Reply With Quote
