Share via


RecoverableErrorReportingContext.RecordRecoverableErrorForChange 方法

记录尝试对某项应用变更目出现的可恢复错误。

命名空间: Microsoft.Synchronization.SimpleProviders
程序集: Microsoft.Synchronization.SimpleProviders(在 microsoft.synchronization.simpleproviders.dll 中)

语法

声明
Public Sub RecordRecoverableErrorForChange ( _
    errorData As RecoverableErrorData _
)
用法
Dim instance As RecoverableErrorReportingContext
Dim errorData As RecoverableErrorData

instance.RecordRecoverableErrorForChange(errorData)
public void RecordRecoverableErrorForChange (
    RecoverableErrorData errorData
)
public:
void RecordRecoverableErrorForChange (
    RecoverableErrorData^ errorData
)
public void RecordRecoverableErrorForChange (
    RecoverableErrorData errorData
)
public function RecordRecoverableErrorForChange (
    errorData : RecoverableErrorData
)

参数

异常

异常类型 条件

SimpleProviderInvalidOperationException

出现了多个可恢复错误,或者对于不再有效的对象尝试了变更。

示例

下面的代码示例演示 DeleteItem 方法的实现,该方法将删除应用于内存中的示例数据存储区。如果无法应用删除,则此方法记录一个可恢复错误。若要在完整应用程序的上下文中查看此代码,请参见"Sync101 using Simple Sync Provider" 应用程序(可从 Sync Framework SDK 和 Code Gallery 获得)。

public override void DeleteItem(ItemFieldDictionary keyAndExpectedVersion, 
    RecoverableErrorReportingContext recoverableErrorReportingContext, 
    out bool commitKnowledgeAfterThisItem)
{
    IDictionary<uint, ItemField> expectedFields = (IDictionary<uint, ItemField>)keyAndExpectedVersion;
    ulong id = (ulong)expectedFields[CUSTOM_FIELD_ID].Value;
    if (_store.Contains(id))
    {
        _store.DeleteItem(id);
    }
    else
    {
        // If the item to delete does not exist, record an error on this change and 
        // continue with the rest of the session.
        recoverableErrorReportingContext.RecordRecoverableErrorForChange(new RecoverableErrorData(new Exception("Item not found in the store")));
    }
    commitKnowledgeAfterThisItem = false;
}
Public Overrides Sub DeleteItem(ByVal keyAndExpectedVersion As ItemFieldDictionary, ByVal recoverableErrorReportingContext As RecoverableErrorReportingContext, ByRef commitKnowledgeAfterThisItem As Boolean)
    Dim expectedFields As IDictionary(Of UInteger, ItemField) = DirectCast(keyAndExpectedVersion, IDictionary(Of UInteger, ItemField))
    Dim id As ULong = CULng(expectedFields(CUSTOM_FIELD_ID).Value)
    If _store.Contains(id) Then
        _store.DeleteItem(id)
    Else
        ' If the item to delete does not exist, record an error on this change and 
        ' continue with the rest of the session. 
        recoverableErrorReportingContext.RecordRecoverableErrorForChange(New RecoverableErrorData(New Exception("Item not found in the store")))
    End If
    commitKnowledgeAfterThisItem = False
End Sub

请参阅

参考

RecoverableErrorReportingContext 类
RecoverableErrorReportingContext 成员
Microsoft.Synchronization.SimpleProviders 命名空间