Bug: SessionProgressEventArgs.PercentCompleted not calculated properly RRS feed

  • Question

  • The calculation for SessionProgressEventArgs.PercentCompleted is buggy:

    The values for PercentCompleted are calculated in SyncAgent.DataSynchronize() like this (code from Reflector):

    num2 = (15 + ((40 / uploadMetadata.Count) * i))


    (in download stage, 15 is replaced with 55)

    (see Microsoft.Synchronization.SyncAgent.DataSynchronize() in assembly Microsoft.Synchronization.Data)


    The problem is, that


    40 / uploadMetadata.Count


    seems to return a truncated Integer value. So for uploadMetadata.Count > 40, this value is always zero.

    This results in the calculated progress value always being 15 (upload) or 55 (download).


    I tested this with Sync Framework versions 1.0 and 3.1.

    I verified it for the download stage, since there are only 28 tables being uploaded but 58 tables being downloaded in my project
    (PercentCompleted gets stuck at 55% for the whole download stage, then jumps to 100%)


    Since I can't really fix this problem myself, does anyone have an idea how to get the data needed to calculate progress?

    The SessionProgressEventArgs provides BatchNumber/BatchCount, but they are reset after each table (BatchNumber is 0 before changes are applied and 1 afterwards; BatchCount is always = 0)

    Thursday, April 14, 2011 11:31 AM

All replies

  • I have found a (pretty dirty) workaround to calculate the progress value properly:

    The basic idea is to intercept the SessionProgress event by overriding OnSessionProgress and calling the base class method with a patched version of the SessionProgressEventArgs.

    Unfortunately, the only indication of progress (except from PercentCompleted) that is available outside of the internal DataSynchronize() method is the current group's name.

    So my solution is to get the lists of groups the same way as DataSynchronize(), which is by calling the internal GetDownloadMetadata()/GetUploadMetadata() functions through reflection.

    Using those lists, I can find the index of the group currently being processed and thus calculating the progress value with (index / count).

    Thursday, April 14, 2011 3:42 PM