I have an .EXE application function function that reads files in a directory within a directory. It then pushed function to put the files in a db. then after the loadimages function does that, it loops through the directory it just loaded into the db and deletes them from the directory. Now sometimes when this exe is run there is no error, but other times there is an error. Does any body have an idea of why this is happening sometimes, but not everytime? Also, does anyone know how to fix this issue?
I am attaching the function that is receiving the error and the full error received.
FULL ERROR RECEIVED:
************ Job: Started At Mon 04/05/2010 18:30:14.89 *********
********* Step 1: Started At Mon 04/05/2010 18:30:15.00 *********
C:\>"\\msilsh0010V049\TAGJobs\1IAM_MailGetWork_C\MailGetWork.exe" /A ENV=Prod /A LogPath="\\msilsh0010V049\TAGJobs\1IAM_MailGetWork_C\Logs\" /A TRN=MMTG1IAMP001,11210 /A MAILSRC=\\msilsh0010V049\TagFileNet\MailWF
Unhandled Exception: System.IO.IOException: The process cannot access the file '\\msilsh0010V049\TagFileNet\MailWF\ScannedImages\LMO2010-04-05155003\INDEX.TMP' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.Delete(String path)
at MailGetWork.GetWork.deleteAllFiles(String dir)
at MailGetWork.GetWork.LoadScannedImages(String Env, String MailSrc)
********* Step 1: Finished At Mon 04/05/2010 18:31:40.42 *********
FUNCTION WHERE THE ERROR IS COMING FROM
Private Function LoadScannedImages(ByVal Env As String, ByVal MailSrc As String) As Boolean
Dim DepartmentFolder() As String
Dim FileFolder() As String
Dim Path As String
Dim i As Integer
Dim ErrorInDepartment, ErrorInScannedImages, MailDoc As Boolean
ErrorInScannedImages = False
Path = MailSrc & "ScannedImages"
DepartmentFolder = Directory.GetDirectories(Path, "*")
For i = 0 To DepartmentFolder.Length - 1
ErrorInDepartment = False
MailDoc = True ' Some images are handled outside MailWF
If UCase(Mid(DepartmentFolder(i), InStrRev(DepartmentFolder(i), "\") + 1, 3)) = "SBP" Then MailDoc = False
If MailDoc Then
ErrorInDepartment = LoadDepartmentMail(DepartmentFolder(i))
If File.Exists(DepartmentFolder(i) & "\INDEX.DAT") Then
File.Delete(DepartmentFolder(i) & "\INDEX.DAT")
If ErrorInDepartment Then
ErrorInScannedImages = True
WriteToLogFile(LogFileName, "Error in folder " & DepartmentFolder(i) & ". Folder not processed.")
WriteToLogFile(LogFileName, "Bypassing " & DepartmentFolder(i))
FileFolder = Directory.GetFiles(Path, "*") ' Scanner places a file in folder with
For i = 0 To FileFolder.Length - 1 ' stats of scan. Don't need it so delete.