Code behind File System Watcher
-
Hello All -- I am trying to watch a folder for any changes to it. I am integrating my code with a CAD application to make modifications to a model depending on the changes occuring in the watched folder. So, to watch a folder I make use of filesystemwatcher. But when I do that, there are some problems occuring with CAD Application. Without filesystemwatcher this works perfectly fine. Now I use timer to see any changes in that folder. Searching over the net, many told that there are some bugs in filesystemwatcher. Does anybody have the code that is behind FileSystemWatcher ? Thanks, Thomas.
-
Hello All -- I am trying to watch a folder for any changes to it. I am integrating my code with a CAD application to make modifications to a model depending on the changes occuring in the watched folder. So, to watch a folder I make use of filesystemwatcher. But when I do that, there are some problems occuring with CAD Application. Without filesystemwatcher this works perfectly fine. Now I use timer to see any changes in that folder. Searching over the net, many told that there are some bugs in filesystemwatcher. Does anybody have the code that is behind FileSystemWatcher ? Thanks, Thomas.
How is the FileSystemWatching affecting the application? Unless you are modifying the files in some way there should be no issues, it simply notifies you of a change.
I know the language. I've read a book. - _Madmatt
-
Hello All -- I am trying to watch a folder for any changes to it. I am integrating my code with a CAD application to make modifications to a model depending on the changes occuring in the watched folder. So, to watch a folder I make use of filesystemwatcher. But when I do that, there are some problems occuring with CAD Application. Without filesystemwatcher this works perfectly fine. Now I use timer to see any changes in that folder. Searching over the net, many told that there are some bugs in filesystemwatcher. Does anybody have the code that is behind FileSystemWatcher ? Thanks, Thomas.
Hi, I'm not aware of any bugs in FileSystemWatcher class. There are a few things you may need to know about it though: - one file operation may result in several FSW chanes being triggered; e.g. a big write may touch several sectors and clusters; more info is here: FileSystemWatcher - Pure Chaos (Part 1 of 2)[^] - there is no "file operation done" signal; so if your app needs to read a newly written file, a simple write event isn't sufficient. A common solution is to use another (small) file as a signal: watch for file B being created; create big file A; when done create small file B causing a signal. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Hello All -- I am trying to watch a folder for any changes to it. I am integrating my code with a CAD application to make modifications to a model depending on the changes occuring in the watched folder. So, to watch a folder I make use of filesystemwatcher. But when I do that, there are some problems occuring with CAD Application. Without filesystemwatcher this works perfectly fine. Now I use timer to see any changes in that folder. Searching over the net, many told that there are some bugs in filesystemwatcher. Does anybody have the code that is behind FileSystemWatcher ? Thanks, Thomas.
Be aware that some applications strangely create an empty file first, and a few moments later on they open it for writing and write the contents. FileSystemWatcher is very fast, and you may happen to move the file away when it is still empty - if the other application then tries to open it for writing, that application could be stupid enough to cause an exception. Try to create your own watcher class by encapsulating FileSystemWatcher and dealing with empty files and files still being written by the other application, and some more strange things specific of that CAD application.
-
Be aware that some applications strangely create an empty file first, and a few moments later on they open it for writing and write the contents. FileSystemWatcher is very fast, and you may happen to move the file away when it is still empty - if the other application then tries to open it for writing, that application could be stupid enough to cause an exception. Try to create your own watcher class by encapsulating FileSystemWatcher and dealing with empty files and files still being written by the other application, and some more strange things specific of that CAD application.
All -- I thank everybody for dropping in and letting me know the various aspects. I still couldnt figure out why the trouble is happening. I can successfully watch a folder and get the file changed/created/deleted notifications, but when I try opening a file in UG(Unigraphics CAD App) (The next line in code is opening a file in a CAD Application) it throws out an error "Attempt to read or write protected memory." Hence I am forced to use timer. But timer is not a true solution. Probably I can send in the code and a small file to be opened in CAD, but I am dubious, whether somebody will have the CAD App. Code : C# CAD APP: UG NX 5 Thanks and Cheers Thomas