What is Directory Monitor For
Directory Monitor is a windows service that tracks folder changes, such as; file creation, removal, modification or rename. It is able to handle multiple locations at once. There is the ability to watch network shares in addition to local folders. Directory monitor does not execute anything, we have a separate windows service for it, called execution agent. When change happens, the directory monitor inserts a record into the queue table. There is no need to restart the Directory monitor service when the user amends the settings.
Database
Holds the overall status of directory monitor: is it enabled or not and settings for individual threads events to monitor for: filter, waits
Users
Create, amend and delete monitors settings.
Management thread
Responsible for creating, updating and destroying monitor threads.
Monitor thread
Monitors a single directory for changes.
When an event happens, it inserts a record into the queue table.
File usage thread
Creates and runs file usage tasks
When a creation event happens it might take some time to release the file.
(It might take 5 minutes to copy a file)
File usage task
The task is just a procedure that checks if the file is open. For example, one task checks filea.txt, another check filleb.txt and so on. Threads are very heavy and there is OS limitation on how many threads we can create. Creating thousands of threads is definitely a stupid idea. The task is very light and while one task is waiting for x milliseconds another one is being executed. The way it works, it checks if the file is open if it is, it sleeps for some time and checks it again. Once the file is closed or a timeout happens it inserts a record into the queue table. Checking is done by opening a file for writing.