FileSystemWatcher vs. Own file system polling
-
Can any body tell me the advantages and disadvantages of both kinds to get to know if a file is in a specified directory. I have a directory in the network and a application that should work with the file took into the directory. I try to do it with a FileSystemWatcher, but the problem is, if the network connection failed, the FileSystemWatcher did'nt react if the network directory is already available. So i need to reinitialize the FileSystemWatcher in a while again. But i also heard to poll the file system isn't a good idea because it slows the cpu down. (Is it more than the FileSystemWatcher? Can anybody suggest (a good loop time for) polling?) Thank You for your suggestions...
-
Can any body tell me the advantages and disadvantages of both kinds to get to know if a file is in a specified directory. I have a directory in the network and a application that should work with the file took into the directory. I try to do it with a FileSystemWatcher, but the problem is, if the network connection failed, the FileSystemWatcher did'nt react if the network directory is already available. So i need to reinitialize the FileSystemWatcher in a while again. But i also heard to poll the file system isn't a good idea because it slows the cpu down. (Is it more than the FileSystemWatcher? Can anybody suggest (a good loop time for) polling?) Thank You for your suggestions...
-
You could create a thread, spins in a loop and reinitializes the FileSystemWatcher from time to time using Thread.Sleep in between. As FileSystemWatcher uses events this would effectively create a mix of polling and signaling.
-
Can any body tell me the advantages and disadvantages of both kinds to get to know if a file is in a specified directory. I have a directory in the network and a application that should work with the file took into the directory. I try to do it with a FileSystemWatcher, but the problem is, if the network connection failed, the FileSystemWatcher did'nt react if the network directory is already available. So i need to reinitialize the FileSystemWatcher in a while again. But i also heard to poll the file system isn't a good idea because it slows the cpu down. (Is it more than the FileSystemWatcher? Can anybody suggest (a good loop time for) polling?) Thank You for your suggestions...
Another downside of the FSW is that it can only be used with NTFS filesystems (FAT may be possible as well, don't know 100%). So if you're trying to watch a file on a SMB share you won't get any events.
Regards, mav -- Black holes are the places where God divided by 0...
-
Yes i already do so, but i think: 'is this mix good?', isn't it better only to poll the file system instead using the file system watcher?
I would think this is ok, and you can decide how often you poll, just don't do it all the time. You may use a flag for poll-only mode which reduces the polling period and disables the FileSystemWatcher, which would make it kind of universal. You could even call the same callback.