R
Roger Twomey
I am working on a filewatcher application.
The premis is:
User uploads an xml file onto the web server
the filewatcher app sees the xml file
filewatcher app reads the file and inserts records into our sql server
filewatcher app deletes the file.
I am trying to figure out the best method of doing this, so I am adding code bit by bit. Currently I have this:
<code>
Private Sub fsWatcher_Created(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles fsWatcher.Changed
Dim strFileName As String
strFileName = e.FullPath.ToString
EventLog.WriteEntry(Me.ServiceName, Me.ServiceName & " File found = " & strFileName, EventLogEntryType.Information)
Try
File.Delete(strFileName)
Catch ex As Exception
EventLog.WriteEntry(Me.ServiceName, Me.ServiceName & " " & ex.ToString, EventLogEntryType.Error)
End Try
End Sub
</code>
You will notice that I write to the event log when I see the file, then I attempt to delete the file and if it fails I write to the eventlog.
Currently when I write to the event log I get a pattern like this:
File is found
Delete error (file in use by another process)
File is found
Delete error (file in use by another process)
File is found
Delete error (file in use by another process)
it should be noted that I specifically put the log entries 3 times because the do in fact show up 3 times. I don't know why, it certainly isn't logical to me. It should also be noted that SOMETIMES the file deletes, but USUALLY it does not.
Can anyone tell me:
1) Why is it being recorded 3 times.
2) How do I make the filewatcher 'let go' of the file so that I can delete it?
Unfortunately at this point it is rather urgent. I really appreciate any help you can give.
Thanks.
The premis is:
User uploads an xml file onto the web server
the filewatcher app sees the xml file
filewatcher app reads the file and inserts records into our sql server
filewatcher app deletes the file.
I am trying to figure out the best method of doing this, so I am adding code bit by bit. Currently I have this:
<code>
Private Sub fsWatcher_Created(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles fsWatcher.Changed
Dim strFileName As String
strFileName = e.FullPath.ToString
EventLog.WriteEntry(Me.ServiceName, Me.ServiceName & " File found = " & strFileName, EventLogEntryType.Information)
Try
File.Delete(strFileName)
Catch ex As Exception
EventLog.WriteEntry(Me.ServiceName, Me.ServiceName & " " & ex.ToString, EventLogEntryType.Error)
End Try
End Sub
</code>
You will notice that I write to the event log when I see the file, then I attempt to delete the file and if it fails I write to the eventlog.
Currently when I write to the event log I get a pattern like this:
File is found
Delete error (file in use by another process)
File is found
Delete error (file in use by another process)
File is found
Delete error (file in use by another process)
it should be noted that I specifically put the log entries 3 times because the do in fact show up 3 times. I don't know why, it certainly isn't logical to me. It should also be noted that SOMETIMES the file deletes, but USUALLY it does not.
Can anyone tell me:
1) Why is it being recorded 3 times.
2) How do I make the filewatcher 'let go' of the file so that I can delete it?
Unfortunately at this point it is rather urgent. I really appreciate any help you can give.
Thanks.