Uzamčený Asynchronous Syncing

  • 20 มกราคม 2552 10:00
     
     

    Hi,

     

    I'm looking into whether or not the actual Syncing can be done asynchronously. I have a book (Apress Pro Sync Framework, Singh/Kanjilal) which shows the SyncCallbacks class, along with the callback methods (including OnProgressChanged which is ideal for monitoring the progress of long running syncs) but does not show how to implement it.

     

    Also, if I look for this class in Sync Services for Devices (compact framework) I cannot find it. My sync client is a smart device application running on Windows Mobile 6.

     

    How would I go about implementing an asynchronous Sync, and can I obtain callbacks to monitor the progress of the sync?

     

    Many thanks in advance.

    • ย้ายโดย Max Wang_Chinasoft 21 เมษายน 2554 22:29 forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    •  

ตอบทั้งหมด

  • 21 มกราคม 2552 20:21
     
     คำตอบ

    I am not aware of out of the box asynch methods being part of the sync provider.  I ended up writing my own.  It was pretty easy.  Just create a class called SyncManager for example.  Instead of calling the synchronize method directly, run your calls through your SyncManager class.  This class will contain a background worker which dispatches the calls to Synchronize.  Problem solved, now you synchronization occurrs on another thread.  Just make sure to invoke your calls to your UI when handling a synch event.

     

    As for the progress events, there are tons of examples of using them on this website. http://www.syncguru.com/Default.aspx

     

  • 25 มกราคม 2552 8:32
    ผู้ดูแล
     
     

    right. the out of box sync service doesn support async sync. but you can do this in the application level as described in this thread.

     

    thanks

    Yunwen

  • 31 กรกฎาคม 2552 16:30
     
     
    Hi,

    I'm bumping this threading as I'm now at the stage in my project where I need to implement this.

    OverloadedOverrides, thanks for the link - I followed it but couldn't find the information you mentioned though.

    Yunwen, thanks for clarifying that it isn't supported out-of-the-box - you mentioned doing it at the application level "as described in this thread" but there's no thread link.

    Any more help you can give would be gratefully appreciated.

    Many thanks,

    Paul.
  • 1 สิงหาคม 2552 7:40
     
     คำตอบ มีโค้ด
    I think he was referring to the second post (above). You need to create a separate class which acts as a 'Sync Manager' to perform the sync. Within that class, have a method which spawns a new background thread. The new thread makes the call to SyncAgent->Synchronize.

    e.g.

            
    /// <summary>
    /// Update cache asynchronously
    /// </summary>
    public void UpdateCacheAsync()
    {
    if (IsSyncing == false)
    {
    IsSyncing = true; // reset the IsSyncing flag to indicate sync is in progress (don't want multi-instance of sync)

    thr = new Thread(new ThreadStart(this.Sync));
    thr.IsBackground = true;
    thr.Start();
    }
    }

    /// <summary>
    /// Sync the data
    /// </summary>
    private void Sync()
    {
    SyncAgent syncAgent = this.GetSyncAgent();
    try
    {
    SyncStatistics stats = syncAgent.Synchronize();
    this.HandleSyncCompleted(stats);
    }
    catch (Exception ex)
    {
    CAppLogger.LogException(ex);
    this.HandleSyncError(ex);
    }
    }



    • ทำเครื่องหมายเป็นคำตอบโดย PaulMcMurray 4 สิงหาคม 2552 14:32
    •  
  • 4 สิงหาคม 2552 14:32
     
     
    Thanks SunHunter - I've got it working now!

    Much Appreciated!
  • 5 ตุลาคม 2552 14:30
     
     
    Sunhunter, could you post your SyncManager class ?  I read about it in this thread (http://social.microsoft.com/Forums/en-US/uklaunch2007ado.net/thread/aba12aa1-6183-419a-af7c-0446e004f6cb/), but apparently am missing something.

    In my code, I init a SyncAgent, and specify some LocalProvider events and properties. Then I pass the syncagent to the SyncManager.

    I get a CientConnection is null error. If I sync without the syncManager, it is fine.
  • 1 ธันวาคม 2552 20:48
     
     
    Thanks SunHunter - I've got it working now!

    Much Appreciated!
    Paul - Care to share an example ?