467,886 Members | 1,816 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,886 developers. It's quick & easy.

File System Watcher Usage

I am currently writing a Windows service which monitors multiple folders
and processes the files in them accordingly. The folders to be monitored
are stored in a string array.

I can think of 2 ways of determining which folder has had the file
dropped into it and was wondering if there was a better way. The 2
solutions i have are as follows.

1) When the file is picked up by the OnChanged event search the array to
determine the file type (by matching the path the file is in against a
path in the file profile)

2) Create a different event for each file profile (folder being
monitored) and then process accordingly.

I need the application to be easily scalable thus option 2 isnt the best
for me as code changes would be needed for the new file profile which i
am trying to avoid.

If anyone has any better methods they would be appreciated.

Thanks,

Stuart Ferguson

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
  • viewed: 3260
Share:
1 Reply
Hi,
On the contrary I think that the solution 2 is the best for you, create a
collection of FileSystemWatchers and point each one to the directory you
want. if all of them use the same event handler to process the OnChanged
events it;s easier, otherwise it gets more complex

like this:

//member variable
ArrayList watchers= new ArrayList();

void CreateWatchers()
{
foreach( string dir in DirectoryArray)
{
FileSystemWatcher watcher = new FileSystemWatcher ();
watcher.Path = dir;
...
watcher.OnChanged = new ....
watchers.Add( watcher);
}
}
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Stuart Ferguson" <st**************@btinternet.com> wrote in message
news:OI****************@TK2MSFTNGP15.phx.gbl...
I am currently writing a Windows service which monitors multiple folders
and processes the files in them accordingly. The folders to be monitored
are stored in a string array.

I can think of 2 ways of determining which folder has had the file
dropped into it and was wondering if there was a better way. The 2
solutions i have are as follows.

1) When the file is picked up by the OnChanged event search the array to
determine the file type (by matching the path the file is in against a
path in the file profile)

2) Create a different event for each file profile (folder being
monitored) and then process accordingly.

I need the application to be easily scalable thus option 2 isnt the best
for me as code changes would be needed for the new file profile which i
am trying to avoid.

If anyone has any better methods they would be appreciated.

Thanks,

Stuart Ferguson

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ron Vecchi | last post: by
7 posts views Thread by Allen Anderson | last post: by
reply views Thread by Jack David | last post: by
2 posts views Thread by Jack David | last post: by
5 posts views Thread by ToddT | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.