Answered by:
FileSyncProvider events are not raised when a change occurs

Question
-
Hi,
I am trying to create a service that runs in the background, and raises and event whenever a change is detected on one of my source/destination locations. I have the following, and I am seeing that an event is only raised if a change occurs before the line "agent.synchronize()" is executed. If a change occurs after, nothing happens.
Am I missing something? I am using Visual Studio 2005, C#. Thanks a lot for your help.
private static string SourceLocation = @"\\networklocation\Source\";
private static string DestLocation = @"C:\Documents and Settings\local user\My Documents\Destination\";
private FileSyncProvider sourceReplica = null;
private FileSyncProvider destReplica = null;public Main()
{
InitializeComponent();FileSyncScopeFilter filter = new FileSyncScopeFilter();
filter.FileNameExcludes.Add(SourceLocation + "*.id"); // Exclude the id fileGuid sourceId = GetSyncID(SourceLocation + "filesync.ID");
Guid destId = GetSyncID(DestLocation + "filesync.ID");sourceReplica = new FileSyncProvider(sourceId, SourceLocation);
destReplica = new FileSyncProvider(destId, DestLocation);sourceReplica.AppliedChange += new EventHandler<AppliedChangeEventArgs>(sourceReplica_AppliedChange);
sourceReplica.ApplyingChange += new EventHandler<ApplyingChangeEventArgs>(sourceReplica_ApplyingChange);
sourceReplica.DetectedChanges += new EventHandler<DetectedChangesEventArgs>(sourceReplica_DetectedChanges);destReplica.AppliedChange += new EventHandler<AppliedChangeEventArgs>(destReplica_AppliedChange);
destReplica.ApplyingChange += new EventHandler<ApplyingChangeEventArgs>(destReplica_ApplyingChange);
destReplica.DetectedChanges += new EventHandler<DetectedChangesEventArgs>(destReplica_DetectedChanges);
SyncOrchestrator agent = new SyncOrchestrator();
agent.LocalProvider = sourceReplica;
agent.RemoteProvider = destReplica;
agent.Direction = SyncDirectionOrder.DownloadAndUpload;
agent.Synchronize();
}- Moved by Max Wang_1983 Thursday, April 21, 2011 5:39 PM forum consolidation (From:SyncFx - Technical Discussion [ReadOnly])
Wednesday, March 11, 2009 7:59 PM
Answers
-
The FSP or sync framework in general do not provide support for detecting real time changes in the filesystem (or whatever youre store may be). You would have to write/use your own watcher.
-Jesse- Marked as answer by ohanna Friday, March 20, 2009 3:38 PM
Friday, March 13, 2009 12:18 AM
All replies
-
Hi ohanna,
Events will only get raised during the Synchronize() call. Changes are only detected and enumerated during the sync.
-Jesse- Proposed as answer by L Zhou [MSFT]Editor Friday, March 20, 2009 10:24 AM
Thursday, March 12, 2009 6:13 PM -
Thanks Jesse. So, is there any way to get a notification whenever a change occurs, on an on going basis, besides setting up a timer to keep calling the Synchronize()?
Thank you.Thursday, March 12, 2009 6:26 PM -
The FSP or sync framework in general do not provide support for detecting real time changes in the filesystem (or whatever youre store may be). You would have to write/use your own watcher.
-Jesse- Marked as answer by ohanna Friday, March 20, 2009 3:38 PM
Friday, March 13, 2009 12:18 AM -
Thanks for the clarifications Jesse.Friday, March 20, 2009 3:38 PM
-
Hi,
I added a "skippedchangeevent" to both my source and destination filesyncproviders (the rest is pretty much the same as what I had above).
sourceReplica.SkippedChange +=
new EventHandler<SkippedChangeEventArgs>(sourceProvider_SkippedChange);
destReplica.SkippedChange += new EventHandler<SkippedChangeEventArgs>(destProvider_SkippedChange);
I then removed the write privilege on my destination location, and then changed a file on the source location, and I call Agent.Synchronize. I was hoping that the SkippedChange Event would be invoked, but none of the event handlers (AppliedChange, ApplyingChange, SkippedChange) is called as a result. The file at the destination location doesn't get updated.
If I added the write privilege back to my destination location, the AppliedChange event does get invoked, and the file at the destination location gets updated correctly.
Is there something that I missed? Thanks again for your help.Wednesday, April 1, 2009 6:19 PM