Question Cannot delete file - used by another process

Kyle.Allbright

Active member
Joined
Apr 19, 2010
Messages
28
Programming Experience
1-3
I am facing a problem which I believe is due to the garbage collection within .NET.

I have the following conundrum where I am getting files from a folder, adding them to and array and then converting them all into one file.

Once this is done I move this new file elsewhere, and need to delete the previous files.

Here is the simplified code:

VB.NET:
  files(j) = Image.FromFile(fi.FullName)
         'Do what im doing with them...

         'Later on...........
         Directory.Delete(dirnext.FullName, True)
The problem is definatly caused as soon as I load the files into an array, as i have tried to delete the folder directly before, and after they have been loaded.

Thanks guys.

EDIT: Sorry, I thought the problem was resolved, by clearing the array with

VB.NET:
            For Each _image As Image In files
                _image.Dispose()
            Next

But it did not actually fix it, it appears vshost is holding onto it for roughly a minute, then letting go...
 
Last edited:
Back
Top