事务中是否需要同时使用 Dispose() 和 Complete() 方法来实现失败时的回滚?

问题描述 投票:0回答:1

在下面的代码中,我是否需要这两种方法才能在失败时实现回滚?或者

Using
-
End Using
已经涵盖了这种情况?

Public Function ProcessMultipleMessages() As String
    Dim messages = GetObjectFromXml(Of ItemList)()

    Using transaction = CreateTransactionScope()
        For Each message In messages.SpecialItems
            Dim errorMsg = ProcessSingleMessage(message)
            If Not String.IsNullOrEmpty(errorMsg) Then
                transaction.Dispose()  '<--- Here
                Return result
            End If
        Next
        transaction.Complete() '<--- Here
    End Using

    Return String.Empty
End Function
vb.net transactions using
1个回答
0
投票

不,

End Using
之后变量交易将被Dispose。

这是要求您使用它的事情之一。

更多使用

© www.soinside.com 2019 - 2024. All rights reserved.