COM+ 上的属性已重置如果调用 ContextUtil.SetComplete() 则为对象

发布于 2024-10-18 05:02:20 字数 1279 浏览 4 评论 0原文

我已经将两个类部署为 COM+ 组件,假设为 ClassA 和 ClassB。 ClassA 有一些公共属性。 ClassB 为这些属性设置值并调用 ClassA 的方法。该方法本身不会修改属性的值。

调用后,属性值将重置为相应类型的默认值。仅当被调用的方法包含语句 ContextUtil.SetComplete() 时才会发生这种情况。一旦我注释掉该语句,属性的值将保持与方法调用之前相同,这正是我所期望的。

我是否忽略了 COM+ 对象及其上下文的一些基本概念?我希望在任何情况下房产价值都保持不变。

这是代码的简化列表:

Option Strict Off
Option Explicit On 

Imports System.EnterpriseServices

<Transaction(TransactionOption.Required)> _
Public Class ClassA
    Inherits ServicedComponent

    Private _propertyA As String

    Public Property PropertyA() As String
        Get
            Return Me._propertyA
        End Get
        Set(ByVal Value As String)
            Me._propertyA = Value
        End Set
    End Property

    Public Sub MethodA()
        ' Do something
        ContextUtil.SetComplete() ' If this is called the Str property is reset after return from this call
    End Sub
End Class

<Transaction(TransactionOption.Required)> _
Public Class ClassB
    Inherits ServicedComponent

    Public Sub MethodB()
        Dim a As ClassA = New ClassA()
        a.PropertyA = "A"
        a.MethodA() 
        ' After this call the value of a.PropertyA is reset to Nothing if ContextUtil.SetComplete() was called inside MethodA()
    End Sub
End Class

I've got two classes deployed as COM+ components, let's say ClassA and ClassB. ClassA has some public properties. ClassB sets values for those properties and calls a method of ClassA. The method itself does not modify the value of the property.

After the call the values of the properties are reset to default values for the corresponding types. This only happens if the called method includes statement ContextUtil.SetComplete(). Once I comment out the statetment the values of the properties remain same as they were before the method call, which is what I expect.

Do I overllok some basic concept of COM+ objects and their contexts? I would expect the property value to remain the same in any case.

Here's the simplified listing for the code:

Option Strict Off
Option Explicit On 

Imports System.EnterpriseServices

<Transaction(TransactionOption.Required)> _
Public Class ClassA
    Inherits ServicedComponent

    Private _propertyA As String

    Public Property PropertyA() As String
        Get
            Return Me._propertyA
        End Get
        Set(ByVal Value As String)
            Me._propertyA = Value
        End Set
    End Property

    Public Sub MethodA()
        ' Do something
        ContextUtil.SetComplete() ' If this is called the Str property is reset after return from this call
    End Sub
End Class

<Transaction(TransactionOption.Required)> _
Public Class ClassB
    Inherits ServicedComponent

    Public Sub MethodB()
        Dim a As ClassA = New ClassA()
        a.PropertyA = "A"
        a.MethodA() 
        ' After this call the value of a.PropertyA is reset to Nothing if ContextUtil.SetComplete() was called inside MethodA()
    End Sub
End Class

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屌丝范 2024-10-25 05:02:20

您是否尝试过在事务上调用 Commit,即:ContextUtil.MyTransactionVote = TransactionVote.Commit。您可能正在进行更改,然后将上下文设置为在更改实际提交之前完成。

Have you tried calling Commit on the Transaction, IE: ContextUtil.MyTransactionVote = TransactionVote.Commit. It could be that you are making changes and then setting the Context to complete before the changes have actually been committed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文