Windows service and the File System Watcher

Posted on 2005-04-04
Medium Priority
Last Modified: 2012-08-14
Hi there, I am using the File System Watcher within a windows service to process files that are created in a specific directory.
While the service is busy processing a file I want the service to process other files that are created at the same time. At the moment it waits until the first file is processed and then starts with the next file. Is this possible? I put in a doevents on the created event of the file system watcher but to no avail.
Question by:azrakdragon
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

checoo earned 1200 total points
ID: 13696413
you should look at multi threading here, as soon as the file system watcher detects a file it should start the processing in a seperate thread, and while the file is still being processed if another file is detected then the file watcher should spawn a new thread to handle the processing of the file.... i.e. everyfile should be processed by a separate thread, or you could look at the possibility of creating a thread pool
LVL 10

Assisted Solution

makerp earned 800 total points
ID: 13696907
you will need a multithreaded solution. you have two choices here, create a new thread every time your file watcher event fires or create a thread pool of a fixed number of threads and have them pick items from a queue, the event handler can add items to this queue..

the first choice is easiest to implement but if you have a flurry of files then you will have lots of threads started, too many and this may not be the most efficent way to process them. remeber each thread carries an overhead in context switches etc that cost in CPU time.

the second choice will involve you creating a Thread Pool and have the threads wait on a queue. your event handler can then post items to the queue.

I think .NET has a threadpool ready to go - see this link


Author Comment

ID: 13704323
Many thanks. Works great now.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question