Hello,
I am running into a problem with my code and can't seem to figure out the
solution.
I know it has to do with the pciture box control and unloading the image
inthe picture box but I can't seem to figure out the correct way to "unload"
the file.
I have a simple form with a picture box and a button. I am using dir() to
get all the the .tif files and display them in the pciture box. Each time the
button it pressed it displays the next TIF image and then tries to kill() the
previous TIF file. Attempting to kill the TIF file produces an IO exception
that "The process cannot access the file becasue it is being used by another
process".
Here is a sample of the code with the bug:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim docPath As String = "C:\Loader Test\"
If (Button1.Text = "Start") Then
currentFile = Dir(docPath + "*.tif")
If (IsNothing(currentFile) = False) Then
Button1.Text = "Process"
PictureBox1.Image = System.Drawing.Image.FromFile(docPath + currentFile)
Return
Else
'
' message box stating that no files to process
'
Return
End If
End If
'
' Button text box is "Process"
'
PictureBox1.Image = Nothing
newFile = Dir()
'
' Kill current file causes Exception
' This proess cannot access the file becasue
' it is being used by another process.
'
Kill(docPath + currentFile)
currentFile = newFile
PictureBox1.Image = System.Drawing.Image.FromFile(docPath + currentFile)
Return
End Sub
Any answers on how to "unload" the image file.
Thanks