FileSystemWatcher Event problem
(Tuesday, September 14, 2004)
Found the following interesting discussion in the Newsgroups:
FileSystemWatcher Event problem by:celebrateyogesh@Yahoo.co.uk (yogesh)
| hello
I getting problem in FileSystemWatcher , I had wrriten the code for the FileSystemWatcher , when i dropping the new file in the directory , the WatcherEdi_Created event get fired , but some time it not get fired. also this happens with muliple files dropping in same folder . the count of events not equal to number of files droped.Follwing i scode snippet. please do the needfull for me.
thank in advance.
Yogesh
Private Sub WatcherEdi_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles WatcherEdi.Created Dim fileObj As IO.File Dim FileAccessed As Boolean Dim strGuid As String
Try While Not FileAccessed strISACtrlNum = "" Try ' Check for 850 file If get850(e.FullPath) Then Call getSenderId(e.FullPath) Call getInterChangeControlNum(e.FullPath) fileObj.Move(e.FullPath, renamedEdiFilePathEdi & "Edi " & strISACtrlNum & ".edi") FileAccessed = True fileObj = Nothing Count = Count + 1 Else
If get997(e.FullPath) Then If getInvoice(e.FullPath) = True Then ' MsgBox(getInvoicenumber(e.FullPath)) 'UpdateInvoiceAck(getInvoicenumber(e.FullPath))
End If End If strGuid = (System.Guid.NewGuid.ToString) fileObj.Move(e.FullPath, OtherEdifilePath & "\" & strGuid) FileAccessed = True fileObj = Nothing
End If Catch ex As System.IO.IOException FileAccessed = True fileObj = Nothing Exit Try End Try End While
Catch ex As Exception Dim funname = "WacherEDI" Trace.WriteLine(ex.Message + "Reported In Function: " + funname + " at: " + DateTime.Now.ToString) Trace.Flush() Finally End Try
End Sub
| | | Reply: by:Les Smith
| | | yogesh According to the code that you sent, you are using a module level Count variable. Be aware that your event code can be running several instances at once. In other words the event is going to fire every time a file is dropped and the code will be running logically multithreaded so you keep this in mind. I don't know what some of the methods that you are calling are doing, but it appears that not all paths of your code update Count.
I use the FileWatcher in a mission critical application and have never seen an instance where a file being dropped was not being recorded. I run the FileWatcher in a service on the server that I am watching and write the list of files to a file on that drive. As long as the server is up, the service is running and the FileWatcher is on. I have another program that renames and reads the file written by the service and updates database with the file information. I do this so that the FileWatcher program will never go down as long as the server is running.
See my article on this subject at http://www.knowdotnet.com/articles/filewatcherservice.html
HTH Les Smith
|
Posted by Xander Zelders

|
|
|
|
0 Comments:
Post a Comment
<< Home