473,788 Members | 3,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows Service - FileSystemWatch er

I'm trying to implement a FileSystemWatch er from a Windows Service.
Everything works until I:

Stop the Service
Copy a file to the watched directory.
Re-Start the Service.

I would expect the watched directory, which has a file in it to start
processing, but it does not. Is there some trick to this?
Nov 17 '05 #1
2 5693
Nick,

When you stop your service, are you shutting down your instance of the
file system watcher? I would think that if this is the case, then that's
what should happen.

The file system watcher is good only for watching events as they happen,
not for determining what files are currently changing.

If you want that behavior, then you will have to create a list of files
that are in the directory when the service shuts down. On restart, you have
to iterate through the list, and then find out what files changed, and then
process them accordingly.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Nick K." <ni*******@yaho o.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I'm trying to implement a FileSystemWatch er from a Windows Service.
Everything works until I:

Stop the Service
Copy a file to the watched directory.
Re-Start the Service.

I would expect the watched directory, which has a file in it to start
processing, but it does not. Is there some trick to this?

Nov 17 '05 #2
The FileSystemWatch er looks only for files created while it is
instantiated, not files created since it last existed. If the directory
were to contain a mix of processed and unprocessed files, how would the
watcher know which ones had been created since it last ran?

When your service starts up, it must create the FileSystemWatch er, then
process all files already in the directory.

Here, we use renaming to make the whole thing work smoothly. Producer
programs create the file in the target directory with a .tmp suffix,
then rename them to their permanent names after the file is completed
and closed. The FileSystemWatch er then notices the file and picks it up
for processing.

As soon as the consumer finishes processing the file, it either deletes
it or renames it with a .done extension, or something like that.

That way if the service ever crashes and restarts, it can always find
all of the appropriately named files and start processing them right
away, secure in the knowledge that none of them are half-built, and
none of them has completed processing.

Nov 17 '05 #3

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

Similar topics

0
1318
by: Lloyd Sheen | last post by:
I have created a FileSystemWatcher application that monitors a set of folder for changes. This works well as a windows app. I have copied the code from the windows app to a windows service and now there are problems. If I perform add/chg/del in the folder, the windows app captures all changes (actually to a degree that I did not know happened - ie. 4 events for an add of a file). The windows service though will not pick up add's to...
1
2187
by: Rich Miller | last post by:
Previously posted on the VB newsgroup with no replies, so any ideas appreciated. I have written a service application in VB (VS.Net 2003). On start, the service creates an object that instantiates a System.IO.FileSystemWatcher like so (the _watcher is declared at the class level as Private and no WithEvents): ' construct the file watcher _watcher = New FileSystemWatcher _watcher.Path = WatchPath _watcher.NotifyFilter =...
3
7841
by: Craig Thompson | last post by:
I've attempted to write a windows service that creates one FileSystemWatcher for each entry in a XML config file. Everything start perfrectly and runs as I expect for about 5 minutes and then after that the FileSystemWatchers seem to stop monitoring... My theory is that for some reason the Garbage Collector is trashing my FileSystemWatchers. Another clue to my situation is that I just took my service and made it into a windows form...
2
2282
by: Bonnett | last post by:
I have made a simple console application that creates a webpage from my playlist, then uploads it to my webhost. I decided to convert it to a windows service and use the FileSystemWatcher to monitor the playlist file, this is where i became stuck. I know the service detects changes to the playlist as when running the Change event of FileSystemWatcher, I add an item to the event log. I've tried making the service without including the...
3
15803
by: Vinny | last post by:
Hey all. I'm now attributing the problem I'm having to something incredibly simple, to which I must be overlooking. I created a Windows Service application that listens for files. The file paths are in a config file. I then write information out to an event log so as files are dropped into their location, I receive information. Lastly, I wish to delete the file(s) once they are dropped .. This is where I'm getting the awkward behavior. I...
0
1228
by: Rich Miller | last post by:
Any ideas appreciated. I have written a service application in VB (VS.Net 2003). On start, the service creates an object that instantiates a System.IO.FileSystemWatcher like so (the _watcher is declared at the class level as Private and no WithEvents): ' construct the file watcher _watcher = New FileSystemWatcher _watcher.Path = WatchPath _watcher.NotifyFilter = (NotifyFilters.FileName Or NotifyFilters.Size Or...
3
1934
by: Trevor | last post by:
This is driving us mad - please help! Back in 2003, I coded a Windows Service in VB.NET for framework v1.1.4322. I deployed it in Nov. 2003, and it worked fine until the end of May 2005, when it choked (see below). We restarted it, and it worked fine for another 7 months until it choked again at the end of Dec. 2005. It has now failed again (mid Feb. 2006). So it's failing more frequently now? OnStart, the service reads a number of...
2
2460
by: Trevor | last post by:
Argh! This problem is driving me nuts! Can you help? In November of 2003, I installed a web service on Windows Server 2003 built in VB.NET for v1.1.4322 of the framework. It contains a timer (System.Timers.Timer) which has an interval of 24 hours. Actually, it reads a time like 2AM out of the config file, and calculates the time between the start of the service to 2AM, and sets the timer. When the timer expires, it re-reads the...
1
4765
by: Rocky | last post by:
I have created a windows service using vb.net which uses a filesystemwatcher to monitoe files in a specifc directory, if images are added to the directory they are resized and saved in a remote directory. The original file is then backed up and deleted from the image directory. The code is as follows Friend Shared Sub ResizeImage(ByVal path As String, ByVal filename As String)
6
595
by: Chris Marsh | last post by:
All I have a database table, changes to the data within which I am interested in acting on. The approach that I'm taking is to have the database update a file every time data is updated. This process is outside my domain - I can rely on the file being updated when data changes. Within my domain is the design of a Windows service to perform the operations required when the data changes. I have not produced a Windows service before...
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10172
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.