none
How to stop SyncAgent.Synchronize processing? RRS feed

  • Question

  • I currently use version 1.0 of the Sync Framework to sync a Sql CE database with a Sql Server database over WCF.  The synchronization process can take a long time to complete therefore during the processing I display a progress bar.  Previously I did not allow the user to cancel the synchronize process but now there is a requirement to allow the user to cancel the sync process.  Is it possible to cancel the SyncAgent.Synchronize() process while it is running?  If so can you please tell me how?  Thank you.
    Thursday, March 4, 2010 9:44 PM

Answers

  • I apologize for the confusion. I mistakenly thought SyncOrchestrator even though you clearly stated SyncAgent.

    Unfortunately, SyncAgent has no cancellation method. I would suggest some workaround to simulate cancelling.

    1. subscribe to an event in which you would throw an exception. Do not set the providers to null as this will throw NullReferenceException as you have seen. Throw a customized exception, instead.

    2. stop the current thread during an event.

    Hope this helps,

    Patrick


    • Marked as answer by dsboyd1 Friday, March 5, 2010 4:12 PM
    Friday, March 5, 2010 12:58 AM

All replies

  • Hello dsboyd1,

    SyncOrchestrator has cancel method which you can call during an event. e.g. ApplyingChangesEventArgs has Session property you can call cancel during sync.

    Patrick

    Thursday, March 4, 2010 10:18 PM
  • If it was easy as replacing my SyncAgent instance with a SyncOrchestrator then I would go that route.  Is it possible to stop the SyncAgent.Synchronize() process?  I have some hack logic to do it but I do not like it.

    My hack logic does the following:
    1. Subscribe to SyncAgent.SessionProgress event.
    2. Call SyncAgent.Synchronize() method.
    3. To cancel the process wait for the next SessionProgress event and set SyncAgent.LocalProvider and SyncAgent.RemoteProvider to null.  This causes the SyncAgent.Synchronize() method to raise a null reference exception which I handle.
    Thursday, March 4, 2010 10:52 PM
  • I apologize for the confusion. I mistakenly thought SyncOrchestrator even though you clearly stated SyncAgent.

    Unfortunately, SyncAgent has no cancellation method. I would suggest some workaround to simulate cancelling.

    1. subscribe to an event in which you would throw an exception. Do not set the providers to null as this will throw NullReferenceException as you have seen. Throw a customized exception, instead.

    2. stop the current thread during an event.

    Hope this helps,

    Patrick


    • Marked as answer by dsboyd1 Friday, March 5, 2010 4:12 PM
    Friday, March 5, 2010 12:58 AM