Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FileSystemWatcher behavior

Posted on 2006-10-19
11
Medium Priority
?
256 Views
Last Modified: 2012-08-14

I wonder if anyone out there can confirm and explain two of my observations about FileSystemWatcher:

a) if I have a process that is continuously writing to a file for some period of time, it doesn't report an event until the process is done, then it will report a change.
b) it seems to miss file deletes if I delete it from a DOS window, but it will catch the delete if I delete it from Windows Explorer

Thanks...
0
Comment
Question by:riceman0
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 

Author Comment

by:riceman0
ID: 17771692

Addendum: it is because of these two facts that I have changed my watcher mechanism to a timer-based function that continuously checks the file size.  Pretty inelegant, eh?
0
 
LVL 9

Expert Comment

by:jrscherer
ID: 17775074
Hi riceman0
What NotifyFilter do you use?
try  FileSystemWatcher1.NotifyFilter = NotifyFilters.LastWrite
Jack.net
0
 
LVL 9

Expert Comment

by:jrscherer
ID: 17775087
Oh, I forgot,
Yes, I made the same experience. Changes made in a Dos window (CMD) will not trigger the File System Watcher.
Jack.net
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:riceman0
ID: 17775148

I've tried a variety of filters, similar results.  Do you know if it's supposed to catch changes by other processes/apps?  Or just by the user through the windows shell?  MSDN isn't entirely clear on that...
0
 

Author Comment

by:riceman0
ID: 17775244

And... changes made in Notepad DO trigger the FileSystemWatcher... what's the difference?  
0
 
LVL 9

Expert Comment

by:jrscherer
ID: 17776169
I do a lot of inter-process communication using the file system watcher. It works between processes / applications. It also works if the file is altered by a service.
Jack.net
0
 

Author Comment

by:riceman0
ID: 17776215

Any idea why not the DOS window then?  It's just another process, I would think.

Also, seen anything similar to my observation (a)?
0
 
LVL 9

Expert Comment

by:jrscherer
ID: 17776358
a) I found some missing event reporting using the Dos (CMD) window. But I did not follow up on this, since it was not an operational issue.

b) Question: do you close the write process between write statements? It will only report a write event if the write process closes. You can't access a file anyhow as long as the write process is not closed and the file is open for write by your porcess.
0
 

Author Comment

by:riceman0
ID: 17776516

The other process keeps it open and writes to it every cycle until it is done with it.  Actually I've found I can access it (for reading) while it is opened for writing by the other process, if I open it with a shared flag as follows:

Dim fs As New FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
0
 
LVL 9

Accepted Solution

by:
jrscherer earned 1500 total points
ID: 17777056
Yes, you can do this with FileShare.ReadWrite, but you have to be aware that you may read incomplete information.

If you keep the file open between writes, the FileSystemWatcher can not be used to check porgress of the write process. Then your file-size method is probably the best alternative.
Jack.net
0
 

Author Comment

by:riceman0
ID: 17777075

Thanks.  You've got at least a share of the points... I'll keep this open a bit to see if anyone has an insight as to why a delete from the DOS window doesn't (and therefore which other programs might not) trigger the FileSystemWatcher...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question