none
FileSyncProvider keeps detecting changes RRS feed

  • Question

  •  static void Main(string[] args)
    
            {
    
                FileSyncOptions option = FileSyncOptions.ExplicitDetectChanges | FileSyncOptions.CompareFileStreams;
    
                FileSyncScopeFilter filter = new FileSyncScopeFilter();
    
                FileSyncProvider provider = new FileSyncProvider(new Guid("{6413337A-2F05-4c5e-A7CF-2337CE4F4B0C}"), @"c:\SomeFolder", filter, option);
    
                provider.DetectedChanges += new EventHandler<DetectedChangesEventArgs>(provider_DetectedChanges);
    
                provider.DetectChanges();
    
                provider.DetectChanges();
    
            }
    
    
    
            static void provider_DetectedChanges(object sender, DetectedChangesEventArgs e)
    
            {
    
                Console.WriteLine("Total files found:" + e.TotalFilesFound.ToString());
    
            }
    
    
    The above code detects ALL files under the folder as "changed", even though there's nothing changed.
    The code stopped reporting false positives till I added:

    filter.AttributeExcludeMask =

    FileAttributes.Archive;

    Anyone know what's the reason of this behavior?
    Thursday, March 18, 2010 1:23 AM

Answers

  • you could turn on auditing on a file to see who is touching it.
    Thursday, March 18, 2010 8:26 PM
    Moderator
  • OK. I traced the sync framework and found that GetIsLocalFileChanged returned 0 for all the files. So there WERE no changes detected. Then I looked at documentation of DetectedChangesEventArgs.TotalFilesFound property. It says: "Gets the total number of files that are found during change detection." Ha! It doesn't say number of *changed* files, but *total number of files*.

    The reason I "Stopped false positive" was because I excluded all files (because of the archive attribute).

    So the whole thing is a stupid misunderstanding after all!!!!!!!

    Thanks Sid for help!
    Thursday, March 18, 2010 10:35 PM

All replies

  • It is possible there is another program or utility that is touching that file and setting the bit. It could be anti-virus program or xcopy or something else?
    Thursday, March 18, 2010 5:22 PM
    Moderator
  • There's no anti-virus or xcopy. The only thing I can think of is that the folder is indexed.

    Thursday, March 18, 2010 6:35 PM
  • you could turn on auditing on a file to see who is touching it.
    Thursday, March 18, 2010 8:26 PM
    Moderator
  • I used FileMon to monitor my local folder. Sure enough, SearchProtocolHost.exe (Windows Search service) accesses the folder once a while. I stopped the service and observed no other process operates on the folder. Then I tried a common folder: C:\Users\Public\Pictures\Sample Pictures - go the same behavior: FileSyncProvider constantly detects changes unless Archive attribute is filtered out.

    Note in the above code I'm calling DetectChanges() multiple times and I get consistant results (all files are changed). I tried to call the method in a loop for 20 times, same result.
    Thursday, March 18, 2010 9:45 PM
  • OK. I traced the sync framework and found that GetIsLocalFileChanged returned 0 for all the files. So there WERE no changes detected. Then I looked at documentation of DetectedChangesEventArgs.TotalFilesFound property. It says: "Gets the total number of files that are found during change detection." Ha! It doesn't say number of *changed* files, but *total number of files*.

    The reason I "Stopped false positive" was because I excluded all files (because of the archive attribute).

    So the whole thing is a stupid misunderstanding after all!!!!!!!

    Thanks Sid for help!
    Thursday, March 18, 2010 10:35 PM
  • ah - glad to know you got to the bottom of this
    Friday, March 19, 2010 12:09 AM
    Moderator