What exactly is FileWatcher doing? When you drop 100 files in a folder it
is watching, it normally will fire of the event 100 times.
In my case, I do all my processing on the first event so I don't need to
reinitialize all my variables for each file. Normally 50 - 100 files will
be dropped in the folder at a time.
If I get an error, in my code it moves out to my try/catch code in the
service - handle it and then exit. Then the next event should fire (and
normally it will). Sometimes however it will just stop firing the event.
It is still running, which I know because the next time I drop a file in the
folder it fires the event.
How is it keeping the events? Is it storing them up as events in a
multiclass delegate fashion? If so, is there a way to see how many more
events are left to fire.
I need to figure out what is happening and how the events could stop firing.
At the moment, I am going to add a loop to keep checking until all the files
are done to fix the problem.
Btw, I have a it pointing at a function when the event fires. I assume that
the next event won't fire until I exit that function. Correct?
My code is:
*************** *************** *************** *************** *******
Imports System.IO
Imports FieldNameMapSet up
Public Class ServiceApp
Private fileWatcher As FileSystemWatch er
Private fieldNameSetup As FieldNameMapSet up.FieldNameMap Setup
Protected Overrides Sub OnStart(ByVal args() As String)
Try
System.Diagnost ics.EventLog.Wr iteEntry(Me.Ser viceName,
Me.ServiceName + " started.", _
System.Diagnost ics.EventLogEnt ryType.Informat ion)
'Use the following line to slow down the onstart to allow you to
attach to the process.
'System.Threadi ng.Thread.Sleep (15000)
InitializeFileW atcher()
Catch ex As Exception
MyException.Pub lish(ex)
End Try
End Sub
Protected Overrides Sub OnStop()
System.Diagnost ics.EventLog.Wr iteEntry(Me.Ser viceName, Me.ServiceName
+ " stopped.", System.Diagnost ics.EventLogEnt ryType.Informat ion)
End Sub
Private Sub InitializeFileW atcher()
fileWatcher = New FileSystemWatch er()
fileWatcher.Pat h = MySettings.XMLF ilePath
fileWatcher.Not ifyFilter = NotifyFilters.F ileName
fileWatcher.Fil ter = "*.*"
AddHandler fileWatcher.Cre ated, AddressOf HandleAppraisal s
fileWatcher.Ena bleRaisingEvent s = True
End Sub
Private Sub HandleAppraisal s(ByVal o As Object, ByVal e As
FileSystemEvent Args)
Try
fieldNameSetup = New FieldNameMapSet up.FieldNameMap Setup()
fieldNameSetup. CheckForApprais als()
Catch exc As Exception
fieldNameSetup. MoveFiles(Field NameMapSetup.Fi eldNameMapSetup .fileInProcess,
FieldNameMapSet up.MySettings.E xceptionFilePat h)
Logging.WriteTo Log(MySettings. LogFilePath, exc.Message + "Writing
to: " + FieldNameMapSet up.MuSettings.E xceptionFilePat h + _
Path.GetFileNam e(FieldNameMapS etup.FieldNameM apSetup.fileInP rocess))
End Try
End Sub
End Class
*************** *************** *************** *************** ********
Thanks,
Tom
is watching, it normally will fire of the event 100 times.
In my case, I do all my processing on the first event so I don't need to
reinitialize all my variables for each file. Normally 50 - 100 files will
be dropped in the folder at a time.
If I get an error, in my code it moves out to my try/catch code in the
service - handle it and then exit. Then the next event should fire (and
normally it will). Sometimes however it will just stop firing the event.
It is still running, which I know because the next time I drop a file in the
folder it fires the event.
How is it keeping the events? Is it storing them up as events in a
multiclass delegate fashion? If so, is there a way to see how many more
events are left to fire.
I need to figure out what is happening and how the events could stop firing.
At the moment, I am going to add a loop to keep checking until all the files
are done to fix the problem.
Btw, I have a it pointing at a function when the event fires. I assume that
the next event won't fire until I exit that function. Correct?
My code is:
*************** *************** *************** *************** *******
Imports System.IO
Imports FieldNameMapSet up
Public Class ServiceApp
Private fileWatcher As FileSystemWatch er
Private fieldNameSetup As FieldNameMapSet up.FieldNameMap Setup
Protected Overrides Sub OnStart(ByVal args() As String)
Try
System.Diagnost ics.EventLog.Wr iteEntry(Me.Ser viceName,
Me.ServiceName + " started.", _
System.Diagnost ics.EventLogEnt ryType.Informat ion)
'Use the following line to slow down the onstart to allow you to
attach to the process.
'System.Threadi ng.Thread.Sleep (15000)
InitializeFileW atcher()
Catch ex As Exception
MyException.Pub lish(ex)
End Try
End Sub
Protected Overrides Sub OnStop()
System.Diagnost ics.EventLog.Wr iteEntry(Me.Ser viceName, Me.ServiceName
+ " stopped.", System.Diagnost ics.EventLogEnt ryType.Informat ion)
End Sub
Private Sub InitializeFileW atcher()
fileWatcher = New FileSystemWatch er()
fileWatcher.Pat h = MySettings.XMLF ilePath
fileWatcher.Not ifyFilter = NotifyFilters.F ileName
fileWatcher.Fil ter = "*.*"
AddHandler fileWatcher.Cre ated, AddressOf HandleAppraisal s
fileWatcher.Ena bleRaisingEvent s = True
End Sub
Private Sub HandleAppraisal s(ByVal o As Object, ByVal e As
FileSystemEvent Args)
Try
fieldNameSetup = New FieldNameMapSet up.FieldNameMap Setup()
fieldNameSetup. CheckForApprais als()
Catch exc As Exception
fieldNameSetup. MoveFiles(Field NameMapSetup.Fi eldNameMapSetup .fileInProcess,
FieldNameMapSet up.MySettings.E xceptionFilePat h)
Logging.WriteTo Log(MySettings. LogFilePath, exc.Message + "Writing
to: " + FieldNameMapSet up.MuSettings.E xceptionFilePat h + _
Path.GetFileNam e(FieldNameMapS etup.FieldNameM apSetup.fileInP rocess))
End Try
End Sub
End Class
*************** *************** *************** *************** ********
Thanks,
Tom
Comment