Hi all,
I'm using FileSystemWatcher to monitor folder for changes( new file added). This application is developed as a Windows Services.
The problem is - sometimes it cannot detect the changes that occurred on the folder (new file added).
Is there any tips that I can use to solve this problem...PLEASE?
Below are the codes from my application:
declarations:
When service is started:Code:#Region " Private Variables " Private m_objLog As EventLog Private m_objWatcher As IO.FileSystemWatcher Dim gFTPDirectory As String Dim gFTPFilePrefix As String Dim gQTFSPath As String Dim gobjTProcessStart As New System.Threading.ThreadStart(AddressOf ProcessFilesAtStartUp) Dim gobjTProcess As New System.Threading.Thread(gobjTProcessStart) #End Region
code when folder changed:Code:Protected Overrides Sub OnStart(ByVal args() As String) Try 'initialize new event log m_objLog = New EventLog() 'check if log already exists If Not m_objLog.SourceExists("ExaQFile2QTFS") Then m_objLog.CreateEventSource("ExaQFile2QTFS", "Application") End If m_objLog.Source = "ExaQFile2QTFS" 'read the setting and get the tag list ReadINIFile() 'initialize Watcher m_objWatcher = New IO.FileSystemWatcher() 'Set Path to Watch m_objWatcher.Path = gFTPDirectory 'Set Filter to *.* m_objWatcher.Filter = gFTPFilePrefix & "*.txt" 'Watch Subdirectories m_objWatcher.IncludeSubdirectories = False 'Set Changes to be watched m_objWatcher.NotifyFilter = IO.NotifyFilters.FileName 'Pointer on Sub for events AddHandler m_objWatcher.Created, AddressOf Changed 'Start Watching m_objWatcher.EnableRaisingEvents = True 'prepare for system start up...thread gobjTProcess.IsBackground = True gobjTProcess.Start() Catch e As Exception m_objLog.WriteEntry("[ Message= " & e.Message & ":: Source= " & e.Source & " ] at OnStart", EventLogEntryType.Error) Finally End Try End Sub
when service is stoped:Code:#Region " Subs for Delegate " Private Sub Changed(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Try ProcessFiles() Catch ex As Exception m_objLog.WriteEntry("[ Message= " & ex.Message & ":: Source= " & ex.Source & " ] at Changed", EventLogEntryType.Error) Finally End Try End Sub #End Region
Please feel free to see my code.......Code:Protected Overrides Sub OnStop() Try m_objLog.Dispose() m_objWatcher.Dispose() Catch e As Exception m_objLog.WriteEntry("[ Message= " & e.Message & ":: Source= " & e.Source & " ] at OnStop", EventLogEntryType.Error) End Try End Sub
Thank you very very much in advance for the kindness help and tips.
Regards.




?
Reply With Quote