T
tshad
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 FieldNameMapSetup
Public Class ServiceApp
Private fileWatcher As FileSystemWatcher
Private fieldNameSetup As FieldNameMapSetup.FieldNameMapSetup
Protected Overrides Sub OnStart(ByVal args() As String)
Try
System.Diagnostics.EventLog.WriteEntry(Me.ServiceName,
Me.ServiceName + " started.", _
System.Diagnostics.EventLogEntryType.Information)
'Use the following line to slow down the onstart to allow you to
attach to the process.
'System.Threading.Thread.Sleep(15000)
InitializeFileWatcher()
Catch ex As Exception
MyException.Publish(ex)
End Try
End Sub
Protected Overrides Sub OnStop()
System.Diagnostics.EventLog.WriteEntry(Me.ServiceName, Me.ServiceName
+ " stopped.", System.Diagnostics.EventLogEntryType.Information)
End Sub
Private Sub InitializeFileWatcher()
fileWatcher = New FileSystemWatcher()
fileWatcher.Path = MySettings.XMLFilePath
fileWatcher.NotifyFilter = NotifyFilters.FileName
fileWatcher.Filter = "*.*"
AddHandler fileWatcher.Created, AddressOf HandleAppraisals
fileWatcher.EnableRaisingEvents = True
End Sub
Private Sub HandleAppraisals(ByVal o As Object, ByVal e As
FileSystemEventArgs)
Try
fieldNameSetup = New FieldNameMapSetup.FieldNameMapSetup()
fieldNameSetup.CheckForAppraisals()
Catch exc As Exception
fieldNameSetup.MoveFiles(FieldNameMapSetup.FieldNameMapSetup.fileInProcess,
FieldNameMapSetup.MySettings.ExceptionFilePath)
Logging.WriteToLog(MySettings.LogFilePath, exc.Message + "Writing
to: " + FieldNameMapSetup.MuSettings.ExceptionFilePath + _
Path.GetFileName(FieldNameMapSetup.FieldNameMapSetup.fileInProcess))
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 FieldNameMapSetup
Public Class ServiceApp
Private fileWatcher As FileSystemWatcher
Private fieldNameSetup As FieldNameMapSetup.FieldNameMapSetup
Protected Overrides Sub OnStart(ByVal args() As String)
Try
System.Diagnostics.EventLog.WriteEntry(Me.ServiceName,
Me.ServiceName + " started.", _
System.Diagnostics.EventLogEntryType.Information)
'Use the following line to slow down the onstart to allow you to
attach to the process.
'System.Threading.Thread.Sleep(15000)
InitializeFileWatcher()
Catch ex As Exception
MyException.Publish(ex)
End Try
End Sub
Protected Overrides Sub OnStop()
System.Diagnostics.EventLog.WriteEntry(Me.ServiceName, Me.ServiceName
+ " stopped.", System.Diagnostics.EventLogEntryType.Information)
End Sub
Private Sub InitializeFileWatcher()
fileWatcher = New FileSystemWatcher()
fileWatcher.Path = MySettings.XMLFilePath
fileWatcher.NotifyFilter = NotifyFilters.FileName
fileWatcher.Filter = "*.*"
AddHandler fileWatcher.Created, AddressOf HandleAppraisals
fileWatcher.EnableRaisingEvents = True
End Sub
Private Sub HandleAppraisals(ByVal o As Object, ByVal e As
FileSystemEventArgs)
Try
fieldNameSetup = New FieldNameMapSetup.FieldNameMapSetup()
fieldNameSetup.CheckForAppraisals()
Catch exc As Exception
fieldNameSetup.MoveFiles(FieldNameMapSetup.FieldNameMapSetup.fileInProcess,
FieldNameMapSetup.MySettings.ExceptionFilePath)
Logging.WriteToLog(MySettings.LogFilePath, exc.Message + "Writing
to: " + FieldNameMapSetup.MuSettings.ExceptionFilePath + _
Path.GetFileName(FieldNameMapSetup.FieldNameMapSetup.fileInProcess))
End Try
End Sub
End Class
********************************************************************
Thanks,
Tom