locked
Background sync on worker thread (and update UI during progress) RRS feed

  • Question

  • Hi, I'm part-way through development of an app using C#, .NET 3.5, SQL Server Compact 3.5 & Synchronization Services for ADO.NET. The previous version of my app used XML as a local store but I figured that using SQL Server would give me much better performance, security and leveraging Sync services would remove a lot of headaches in terms of moving data to and from the back-end. After a slow start with the technology, I've finally got to grips with it, the device communicates perfectly and I'm overriding a couple of server events.

    Anyway, now that my sync is working fine synchronously, I wanted to try to move synchronization onto a background thread to allow the UI on my device to continue once a sync is invoked within the application. I've created a SyncManager class as suggested in this thread (http://social.microsoft.com/Forums/en-US/uklaunch2007ado.net/thread/aba12aa1-6183-419a-af7c-0446e004f6cb/). I wanted to use a single instance of this class across my application as I only want to have one sync running at a time. I've created a static property IsSyncing in my SyncManager class to handle this logic.

    All forms in my application inherit from a 'master' form which I call frmMaster (which contains a statusbar which is used across my whole app to show sync progress/success etc). In frmMaster I create a static instance of my SyncManager class and child forms are all wired up to handle the events raised by SyncManager (SyncSucceeded, SyncFailed and SyncProgress).

    When any events are raised by SyncManager, I want the event handlers on my form to update a statusbar on my user interface (e.g. sync completed | sync 30% complete etc). However, because the sync is invoked by a different thread to the user interface and the form that originally invoked the sync might not exist anymore when the sync completes, I am running into errors. No matter what I try to do (I've jiggled my code a 100 times it seems), I just cannot seem to work out to do this. All my forms inherit from frmMaster and they call contain a statusbar which I want to update whenever a SyncManager event is handled.

    If anyone has any small pointers, it would be much appreciated.
    • Moved by Max Wang_1983 Thursday, April 21, 2011 1:22 AM forum consolidation (From:SyncFx - Technical Discussion [ReadOnly])
    Friday, June 26, 2009 1:14 PM

Answers

  • Hi, thanks for your message, I've managed to resolve this now. I had forgotten to release my 'SyncManager' event handlers when closing my forms so I ended up with 'ghost' subscribers to some of the sync services events and this was causing the errors.

    SunHunter
    Tuesday, June 30, 2009 4:23 PM

All replies

  • Hello SunHunter,

    Could you elaborate more on what kind of error you are getting? Have you tried creating a non-static instance of SyncManager?

    Patrick
    Monday, June 29, 2009 4:00 PM
  • Hi, thanks for your message, I've managed to resolve this now. I had forgotten to release my 'SyncManager' event handlers when closing my forms so I ended up with 'ghost' subscribers to some of the sync services events and this was causing the errors.

    SunHunter
    Tuesday, June 30, 2009 4:23 PM