示例1.(如果我的某个方法使用非托管对象)
Public Class Logger
'Implements IDisposable <<< is this necessary because of unmanaged object inside the method?
Public Sub CreateLogFile(ByVal msg As String)
Try
If Not String.IsNullOrEmpty(_LogDir) Then
Try
Using objWriter As New System.IO.StreamWriter(Format(Now, "MM-dd-yyyy HHmmss") & ".txt", True)
objWriter.WriteLine(msg)
objWriter.Close()
End Using
Catch ex As Exception
End Try
End If
Catch ex As Exception
End Try
End Sub
End Class
示例2.(如果我在窗体中声明一个事件)
Public Class frmViewerReport
'Implements IDisposable <<< is this necessary because of event I added in the winform?
Public Event DoneAutoPrint()
Public Event Progress()
Public Event ProgressDone()
Public Event ErrorRaised(ByVal msg As String)
End Class
示例3.(如果我的类使用具有基于dbcontext的类的类)
Public Class MyRepository
'Implements IDisposable <<< is this necessary because of dbcontext?
Private _ctx As New MyEntities
Private _User As User
End Class
Public Class MyEntities
Inherits DbContext
End Class
我知道有很多关于这个问题的话题,我什么时候都找不到具体的样本。
非常感谢您抽出宝贵时间。是/否答案会有所帮助。