473,386 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

FileSystemWatcher Event problem

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
Nov 20 '05 #1
1 1561
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/f...erservice.html

HTH
Les Smith

"yogesh" <ce*************@Yahoo.co.uk> wrote in message
news:82**************************@posting.google.c om...
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

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Josh Usovsky | last post by:
I'm setting up a watched folder using FileSystemWatcher. When I drop a small file into the watched folder, I can respond to a .Created event and process the file with other code. However, if I try...
0
by: cxw0106 | last post by:
Hello, I have some weird problem with the FileSystemWatcher. I have developed an application that monitors a network directory for file changes of a certain file type. The program runs well for...
1
by: Troy Murphy | last post by:
How do I prevent the FileSystemWatcher event to keep firing while the file is being created? When copying a file to the watched folder, the event fires a dozen or more times! Also, the...
1
by: Andreas | last post by:
Hi, we have some problems with the following situation: A remote application A writes files to a directory monitored by a FileSystemWatcher-instance in application B. A creates the file with...
7
by: Allen Anderson | last post by:
I'm trying to figure out a way to catch when a file has been written to a directory. I currently have it where I can catch when the file begins writing, but this isn't helpful as I need to know...
3
by: Stampede | last post by:
Hi, I want to use the FileSystemWatcher in a Windows Service. I read an article, where the author created the FileSystemWatcher object in a seperate thread and when the event is fired, he started...
20
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business...
2
by: kmcnet | last post by:
Hello Everyone and thanks for your help in advance. I have been battling a problem for nearly a month with the FileSystemWatcher component. Basically, what I am trying to do it to monitor three...
9
by: Tushar | last post by:
Followup-To: microsoft.public.dotnet.general Does anyone know when is this event raised, is it: 1) When the file is created but may not have been closed 2) When the file is created AND it has...
1
by: Lila Godel | last post by:
My VB.NET 2008 application is setup with a Sub Main and no forms. At run time a NotifyIcon is created with one context menu choice (Close which terminates app). I have no trouble running the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.