OperationBase.MarkErrorAsHandled 方法
指定在处理操作时遇到错误。
命名空间: System.ServiceModel.DomainServices.Client
程序集: System.ServiceModel.DomainServices.Client(在 system.servicemodel.domainservices.client.dll 中)
用法
用法
Dim instance As OperationBase
instance.MarkErrorAsHandled
语法
声明
Public Sub MarkErrorAsHandled
public void MarkErrorAsHandled ()
public:
void MarkErrorAsHandled ()
public void MarkErrorAsHandled ()
public function MarkErrorAsHandled ()
示例
下面的示例演示了一个针对提交操作的回调方法,用于检查错误并调用 MarkErrorAsHandled 方法。
Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
_customerContext.SubmitChanges(AddressOf OnSubmitCompleted, Nothing)
End Sub
Private Sub RejectButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
_customerContext.RejectChanges()
CheckChanges()
End Sub
Private Sub CustomerGrid_RowEditEnded(ByVal sender As System.Object, ByVal e As System.Windows.Controls.DataGridRowEditEndedEventArgs)
CheckChanges()
End Sub
Private Sub CheckChanges()
Dim changeSet = _customerContext.EntityContainer.GetChanges()
ChangeText.Text = changeSet.ToString()
Dim hasChanges = _customerContext.HasChanges
SaveButton.IsEnabled = hasChanges
RejectButton.IsEnabled = hasChanges
End Sub
Private Sub OnSubmitCompleted(ByVal so As SubmitOperation)
If (so.HasError) Then
MessageBox.Show(String.Format("Submit Failed: {0}", so.Error.Message))
so.MarkErrorAsHandled()
End If
CheckChanges()
End Sub
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
_customerContext.SubmitChanges(OnSubmitCompleted, null);
}
private void RejectButton_Click(object sender, RoutedEventArgs e)
{
_customerContext.RejectChanges();
CheckChanges();
}
private void CustomerGrid_RowEditEnded(object sender, DataGridRowEditEndedEventArgs e)
{
CheckChanges();
}
private void CheckChanges()
{
EntityChangeSet changeSet = _customerContext.EntityContainer.GetChanges();
ChangeText.Text = changeSet.ToString();
bool hasChanges = _customerContext.HasChanges;
SaveButton.IsEnabled = hasChanges;
RejectButton.IsEnabled = hasChanges;
}
private void OnSubmitCompleted(SubmitOperation so)
{
if (so.HasError)
{
MessageBox.Show(string.Format("Submit Failed: {0}", so.Error.Message));
so.MarkErrorAsHandled();
}
CheckChanges();
}
异常
异常类型 | 条件 |
---|---|
InvalidOperationException | HasError 属性为 false。 |
备注
在采取了从域操作中的错误进行恢复所必需的步骤之后,调用此方法。通过调用此方法,指示此错误将不会作为异常引发。如果不针对失败操作调用此方法,则会引发 Complete 方法中指定的异常。
System#ComponentModel#INotifyPropertyChanged#PropertyChanged 事件将针对 IsErrorHandled 属性而引发。
线程安全
此类型的任何公共静态(在 Visual Basic 中为 共享)成员都是线程安全的。不保证所有实例成员都是线程安全的。
平台
开发平台
Windows XP Home Edition, Windows XP Professional, Windows Server 2003 、Windows Server 2008 和 Windows 2000
目标平台
Change History
另请参见
参考
OperationBase 类
OperationBase 成员
System.ServiceModel.DomainServices.Client 命名空间