M
mp
I was recommended to implement Idisposable in a class
I'm not getting the syntax right and don't find an example in help i can
follow
is there a simplified example or can someone see what i should do here?
I have a utility class that gets a reference to an object(acad application)
The main class instantiates the utility class, the utility class gets the
object(acad) and passes to the main class to use
when the main class is done, what is the correct process to tear down the
references to the object?
the main class init sub is as follows:
Function Init() As Boolean
m_Util = New MCSUtil(True) 'create utility class
m_Util.Init2(True)
If m_acad Is Nothing Then
m_acad = m_Util.ACAD 'get reference to object for internal use
End If
If m_acad Is Nothing Then
MsgBox("Can not get AutoCAD instance.", MsgBoxStyle.Exclamation,
"")
Exit Function
End If
m_acadDoc = m_acad.ActiveDocument
If m_acadDoc Is Nothing Then
MsgBox("No active document.", MsgBoxStyle.Information, "")
Exit Function
End If
'if we're still here all is well
Init = True
End Function
in the utility class:
Function Init2(ByVal bDebug As Boolean) As Boolean
m_Debug = bDebug
Try
m_AcadApp =
DirectCast(Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication,
AcadApplication)
m_acadDoc = m_AcadApp.ActiveDocument
Return True
Catch ex As Exception
Return False
End Try
End Function
'the variable declaration in utility class:
Private m_AcadApp As Autodesk.AutoCAD.Interop.AcadApplication = Nothing
which class should implement iDisposable, and how is that sub Dispose
written?
I tried putting in the Utility class:
<System.Runtime.InteropServices.ComVisible(False)> Public Class MCSUtil
Implements IDisposable
Private m_acadDoc As AcadDocument
Private m_AcadApp As Autodesk.AutoCAD.Interop.AcadApplication = Nothing
Private m_Debug As Boolean
Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose()
m_AcadApp = Nothing
m_acadDoc = Nothing
GC.SuppressFinalize(Me)
End Sub
i found this through the help
'Public Overloads Sub Dispose() Implements IDisposable.Dispose
' Dispose(True)
' ' This object will be cleaned up by the Dispose method.
' ' Therefore, you should call GC.SupressFinalize to
' ' take this object off the finalization queue
' ' and prevent finalization code for this object
' ' from executing a second time.
' GC.SuppressFinalize(Me)
'End Sub
but when i try to duplicate thta in my code, the Dispose() method takes no
args so i get a compile error
any help?
thanks
mark
I'm not getting the syntax right and don't find an example in help i can
follow
is there a simplified example or can someone see what i should do here?
I have a utility class that gets a reference to an object(acad application)
The main class instantiates the utility class, the utility class gets the
object(acad) and passes to the main class to use
when the main class is done, what is the correct process to tear down the
references to the object?
the main class init sub is as follows:
Function Init() As Boolean
m_Util = New MCSUtil(True) 'create utility class
m_Util.Init2(True)
If m_acad Is Nothing Then
m_acad = m_Util.ACAD 'get reference to object for internal use
End If
If m_acad Is Nothing Then
MsgBox("Can not get AutoCAD instance.", MsgBoxStyle.Exclamation,
"")
Exit Function
End If
m_acadDoc = m_acad.ActiveDocument
If m_acadDoc Is Nothing Then
MsgBox("No active document.", MsgBoxStyle.Information, "")
Exit Function
End If
'if we're still here all is well
Init = True
End Function
in the utility class:
Function Init2(ByVal bDebug As Boolean) As Boolean
m_Debug = bDebug
Try
m_AcadApp =
DirectCast(Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication,
AcadApplication)
m_acadDoc = m_AcadApp.ActiveDocument
Return True
Catch ex As Exception
Return False
End Try
End Function
'the variable declaration in utility class:
Private m_AcadApp As Autodesk.AutoCAD.Interop.AcadApplication = Nothing
which class should implement iDisposable, and how is that sub Dispose
written?
I tried putting in the Utility class:
<System.Runtime.InteropServices.ComVisible(False)> Public Class MCSUtil
Implements IDisposable
Private m_acadDoc As AcadDocument
Private m_AcadApp As Autodesk.AutoCAD.Interop.AcadApplication = Nothing
Private m_Debug As Boolean
Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose()
m_AcadApp = Nothing
m_acadDoc = Nothing
GC.SuppressFinalize(Me)
End Sub
i found this through the help
'Public Overloads Sub Dispose() Implements IDisposable.Dispose
' Dispose(True)
' ' This object will be cleaned up by the Dispose method.
' ' Therefore, you should call GC.SupressFinalize to
' ' take this object off the finalization queue
' ' and prevent finalization code for this object
' ' from executing a second time.
' GC.SuppressFinalize(Me)
'End Sub
but when i try to duplicate thta in my code, the Dispose() method takes no
args so i get a compile error
any help?
thanks
mark