使用RetryApplyingRow的Sync Framework会导致无限循环

时间:2013-06-03 15:28:39

标签: c# synchronization conflict microsoft-sync-framework syncfx

我正在使用Sync Framework 2.1。我正在实施冲突处理,但我不明白为什么它不起作用:

这是我的冲突处理代码:

public void OnErrorOccured(DbApplyChangeFailedEventArgs e)
{
    if (e.Conflict.Type == DbConflictType.LocalUpdateRemoteUpdate)
    {
        int remoteValue = (int)e.Conflict.RemoteChange.Rows[0][e.Conflict.RemoteChange.Columns["MyValue"]];
        int localValue = (int)e.Conflict.LocalChange.Rows[0][e.Conflict.LocalChange.Columns["MyValue"]];

        if (remoteValue > localValue)
        {
            // Overwrite only MyValue column
            e.Conflict.LocalChange.Rows[0][e.Conflict.LocalChange.Columns["MyValue"]] = remoteValue;

            e.Action = ApplyAction.RetryApplyingRow; // Retry with new changes
            // Same conflict will be raised again and again and again
        }
        else
        {
            // Overwrite entire local record
            e.Action = ApplyAction.RetryWithForceWrite;
            // The else is working properly
        }
    }
}

我还尝试使e.Conflict.RemoteChange等于e.Conflict.LocalChange,将所有值合并到两个DataTables中:

// Overwrite only MyValue column
e.Conflict.LocalChange.Rows[0][e.Conflict.LocalChange.Columns["MyValue"]] = remoteValue;

// Copy rest of all columns
e.Conflict.RemoteChange.Rows[0][1] = e.Conflict.LocalChange.Rows[0][1];
e.Conflict.RemoteChange.Rows[0][2] = e.Conflict.LocalChange.Rows[0][2];
e.Conflict.RemoteChange.Rows[0][3] = e.Conflict.LocalChange.Rows[0][3];

Bot也没有帮助。

- 我的代码出了什么问题?
- 我没有使用RetryApplyingRow找到任何好的考试。你能提供吗?

提前致谢!

0 个答案:

没有答案