我有两个类作为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
答案 0 :(得分:1)
您是否尝试在事务上调用Commit,IE:ContextUtil.MyTransactionVote = TransactionVote.Commit。可能是您正在进行更改,然后在实际提交更改之前将Context设置为完成。