以下示例包含三个 VBA 模块:两个类和一个常规模块。在我运行 RubberDuck VBA 测试然后尝试关闭 Excel 后,Excel 在主动使用 CPU 时挂起。运行一次测试不会每次都重现这个问题,但是当我至少运行两次时,似乎每次都会重现这个问题。
RDVBA 版本 2.5.2.5871
操作系统:Microsoft Windows NT 6.2.9200.0,x64
测试环境一:
主机产品:Microsoft Office XP x86
主机版本:10.0.6501
主机可执行文件:EXCEL.EXE
测试环境二:
主机产品:Microsoft Office 2016 x64
主机版本:16.0.4266.1001
主机可执行文件:EXCEL.EXE
模块测试.bas
'@TestModule
Option Explicit
Option Private Module
Private Assert As Rubberduck.PermissiveAssertClass
#Const USE_ASSERT_OBJECT = True
'@ModuleInitialize
Private Sub ModuleInitialize()
Set Assert = New Rubberduck.PermissiveAssertClass
End Sub
'@ModuleCleanup
Private Sub ModuleCleanup()
Set Assert = Nothing
Debug.Print CStr(Timer()) & ": Assert = Nothing"
End Sub
'@TestMethod("Factory")
Private Sub ztcCreate_VerifiesDefaultManager()
Dim dbm As Class2
Set dbm = Class2.Create(ThisWorkbook.Path)
#If USE_ASSERT_OBJECT Then
Assert.IsNotNothing dbm
#Else
Assert.IsTrue Not dbm Is Nothing
#End If
End Sub
Class1.cls
'@PredeclaredId
Option Explicit
Public Function Create(Optional ByVal DefaultPath As String = vbNullString) As Class1
Dim Instance As Class1
Set Instance = New Class1
Set Create = Instance
End Function
Private Sub Class_Terminate()
Debug.Print CStr(Timer()) & ": Class1 Class_Terminate"
End Sub
Class2.cls
'@PredeclaredId
Option Explicit
Private Type TClass2
DllMan As Class1
End Type
Private this As TClass2
'@DefaultMember
Public Function Create(ByVal DllPath As String) As Class2
Dim Instance As Class2
Set Instance = New Class2
Instance.Init DllPath
Set Create = Instance
End Function
Friend Sub Init(ByVal DllPath As String)
Dim FileNames As Variant
Set this.DllMan = Class1.Create(DllPath)
End Sub
Private Sub Class_Terminate()
Debug.Print CStr(Timer()) & ": Class2 Class_Terminate"
End Sub