none
How to Cancel A Sync Processing of ado.net sync RRS feed

  • Question

  • There is a mothod on SyncOrchestator (Cancel()) that I can call.  When I call it (in a thread safe way), I get the error below.  What is the best way to cancel a running sync?  I may be in the middle of thousands of rows for a give table.

    This operation is not valid in any state of the object except for SyncAgentState.Uploading or SyncAgentState.Downloading.

     

    Orchestrator =
              new SyncOrchestrator
                {
                  LocalProvider = providerSource,
                  RemoteProvider = providerDestination,
                  Direction = SyncDirectionOrder.UploadAndDownload
                };
    
    ...
    
     Orchestrator.Cancel();
    

     


    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider
    Friday, July 30, 2010 8:19 PM

Answers

  • not sure if it will work with the collaboration providers, but in the offline providers, the best way to cancel a sync was to raise an exception in one of the provider's events.
    • Marked as answer by Peter Kellner Monday, August 2, 2010 2:29 AM
    Saturday, July 31, 2010 1:19 PM
    Moderator

All replies

  • have you tried calling the Cancel inside one of the provider's events like the SyncProgress/ApplyingChanges/SelectingChanges?
    • Marked as answer by Peter Kellner Friday, July 30, 2010 11:06 PM
    • Unmarked as answer by Peter Kellner Saturday, July 31, 2010 4:49 AM
    Friday, July 30, 2010 11:03 PM
    Moderator
  • No, but I did figure it out.  The threading issues are a little confusing, but basically, I set a flag from inside the provider progress events, then keep a static handle to the orchestrator and execute the Orchestrator.Cancel() and that seems to very reliable (so far)

    THanks,


    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider
    • Marked as answer by Peter Kellner Friday, July 30, 2010 11:06 PM
    • Unmarked as answer by Peter Kellner Saturday, July 31, 2010 4:49 AM
    Friday, July 30, 2010 11:05 PM
  • Turns out, things are not going well.

    I really need a solid way to end the processing from my BackgroundWorker thread.

    When I call from inside my process events, it seems that the orchestrator is in the wrong state.  I check to make sure it's either uploading or downloading and it seems to not be in either, or when it is, I get a com interop crash error.

    I could really use some guidance on this.  That is, a solid way to abort the processing cleanly.

    Thanks


    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider
    Saturday, July 31, 2010 4:52 AM
  • not sure if it will work with the collaboration providers, but in the offline providers, the best way to cancel a sync was to raise an exception in one of the provider's events.
    • Marked as answer by Peter Kellner Monday, August 2, 2010 2:29 AM
    Saturday, July 31, 2010 1:19 PM
    Moderator
  • Thanks June, throwing an exception solved the problem.
    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider
    Monday, August 2, 2010 2:29 AM