473,396 Members | 1,756 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,396 software developers and data experts.

Filewatcher processing when no files

I have a filewatcher program that is working syncronously (which is how I
want it to work).

But my program will handle whatever files are in the folder at the time it
runs. So when I drop 15 files in the folder at once, the event kicks of 15
times - even though all the files were processed in the 1st event.

This is fine, it just won't find any files in the folder for 14 times.

But if I drop 600 files in the folder at once, it will do about 590+ looks
into an empty folder.

I assume (and we all know what "assume" is) that the filewatcher object is
keeping an array or collection of files that get moved into the folder and
process this list one at a time (runs my program once for each event).

Is there a way to tell filewatcher after I process the 1st event to just
clear it's list or array so it doesn't keep running my program when there is
nothing in my folder?

I was thinking of doing something that would stop filewatcher from looking
at the folder (something like: fileWatcher.EnableRaisingEvents = False)
while I am processing it and then when done (fileWatcher.EnableRaisingEvents
= True) to start watching the folder. But this wouldn't clear out the list
it has so it would still process the 500 events (I think).

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.ServiceN ame,
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.ServiceN ame, 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.FieldNa meMapSetup.fileInProcess,
FieldNameMapSetup.MySettings.ExceptionFilePath)
Logging.WriteToLog(MySettings.LogFilePath, exc.Message + "Writing
to: " + FieldNameMapSetup.MuSettings.ExceptionFilePath + _
Path.GetFileName(FieldNameMapSetup.FieldNameMapSet up.fileInProcess))
End Try
End Sub

End Class
************************************************** ******************

Thanks,

Tom
Jun 27 '08 #1
0 1123

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

Similar topics

4
by: Ron King Jr | last post by:
I have a small problem with my windows service. The first time I start the service everything works the way it's suppose to, but randomly the service fails. The jist of the service is to use the...
0
by: andre | last post by:
I’m trying to use the Filewatcher class in Visual Studio.net. I’m watching an FTP folder looking for a File. The File size is about 200 to 300 megs. When the file is done uploading, I need...
1
by: PeterNZ | last post by:
Hi all, I developped an C# app which is using FileSystemWatcher. If a file is created in a specific folder, it opens the file and does some processing. This functionality works without...
0
by: adam_scheich | last post by:
When creating a file in excel and saving it to a directory that is being watched by filewatcher using Save As, the filewatcher created event doesn't fire. It works fine for text files, but for...
2
by: Roger Twomey | last post by:
I am working on a filewatcher application. The premis is: User uploads an xml file onto the web server the filewatcher app sees the xml file filewatcher app reads the file and inserts...
1
by: ba.hons | last post by:
Hello, I have a file watcher object which i use to check a directory for XML files. When an XML file is placed in the directory i check the filename, to make sure it for me, then parse the...
3
by: ba.hons | last post by:
Hello All. I have a filewatcher object which looks at a shared folder and when a new XML file is placed in this folder the on create method calls a method which reads the XML file and based on...
3
by: tshad | last post by:
Is there some way to have the fileWatcher to initially check the folder to see if there is anything in it (based on the filters)? If I reboot the machine, for example, and it starts up the...
7
by: tshad | last post by:
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...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.