Click here to Skip to main content
15,881,882 members
Articles / General Programming / File
Article

Uses Of FileSystemWatcher

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
11 Oct 2013CPOL1 min read 8.9K   1  
The FileSystemWatcher is responsible for to track the updates of either file or folder/sub-folders, Suppose if I would like to continuously monitor a

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

The FileSystemWatcher is responsible for to track the updates of either file or folder/sub-folders, Suppose if I would like to continuously monitor a folder , something like what are the newly added files or something like what are deleted files or which files are renamed such operations.

It’s not easy task to monitor a folder with old approach creates a service and use the Threading to continuously monitoring the folder. But with this approach needs more CPU and memory attention.

But with The FileSystemWatcher it’s quite easy.

We have one more advantage, Consider the below scenario. I have 2 applications

1.       Quoting application QA(Core Operations) only providing services to others it does not have any other information of any other applications.

2.       Broker application BA(it communicate with other applications by using services)

I have one functionality if user requested quoting from the Broker application and then request ends, user don’t wait till the Quoting application response, it’s like one way communication,  after the Quoting application service process all the requests done by broker application and responds appropriately , then how does Broker applications come to know which requests are done?

Approach 1: Call the BA services after QA completed the request. But with this approach QA doesn’t have any other application service end points. So in this way it won’t work out.

Approach 2: After process the BA request then create a xml file with request information and save it to some shared folder

And run the Windows service with File watcher service option and point out the folder path to the Shared folder path, Now handle the Created event and call the BA services accordingly to track the requested information.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
This is a Collaborative Group

754 members

Comments and Discussions

 
-- There are no messages in this forum --