views:

740

answers:

4

C# FileSystemWatcher does not catch a Perforce revert. It works fine when the same file is modified. This causes a problem because the revert changes the file, but FileSystemWatcher does not get notified.

How do you watch for a Perforce revert?

Thank you.

+1  A: 

Have you set the NotifyFilters appropriately? From the FileSystemWatcher help...

There are several types of changes you can watch for in a directory or file. For example, you can watch for changes in Attributes, the LastWrite date and time, or the Size of files or directories. This is done by setting the NotifyFilter property to one of the NotifyFilters values.

A Perforce revert may also revert to the previous LastWrite time which, if you're only looking for a more recent timestamp, won't trigger an update.

moobaa
A: 

I tried a sample executable from CodeProject, it seems to work, must be my code that's bad...

A: 

I suspect that Perforce report does a copy from a temporary file, so it's not actually writing to the file, but copying in a new file and blowing away the previous one. So since the file isn't being "written to", you don't get the notification. It doesn't help you though :(

Paul Betts
+2  A: 

In addition to checking the NotifyFilters, make sure you're attaching handlers to all of the events that the FileSystemWatcher has. FileSystemWatcher has events for Changed, Created, Deleted and Renamed.

If you're only attaching to the Changed event and not catching any events, then it sounds like Perforce might be deleting and recreating the file. If this is the case, add handlers to the Deleted and Changed events.

The NotifyFilters documentation on msdn has example code showing handling for all of the events.

Matt David