Private Sub btnSalir_Click(sender As Object, e As EventArgs) Handles btnSalir.Click
Try
MsgBox("Conexión cancelada", CType(MsgBoxStyle.Information + MsgBoxStyle.OkOnly, MsgBoxStyle), "Conexión de datos")
Finally
Dispose()
End Try
End Sub
Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Private Sub BtnSalir_Click(sender As Object, e As EventArgs) Handles BtnSalir.Click
Finalize()
MsgBox("Conexión cancelada", CType(MsgBoxStyle.Information + MsgBoxStyle.OkOnly, MsgBoxStyle), "Conexión de datos")
Close()
End
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
' En este procedimiento, existen 2 métodos NEW. Este es la razon porque existen tambien 2 métodos DISPOSE.
' En este caso, ninguno residuo en la memoria.
Dim FraseSql As String = "SELECT * FROM UnaTabla"
Dim MiCon As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=D:\Tmp\MiDB.mdb")
Dim MiAdapter As New OleDbDataAdapter(FraseSql, MiCon)
Dim MiDt As New DataTable("MiDataTabla")
MiAdapter.Fill(MiDt)
' Aqui, tengo los datos en la datatabla MiDt.
' No he mas nécesario de la conexion y del adapter
MiAdapter.Dispose() ' Adapter no tiene el método Close
MiCon.Close() ' Connection tiene el método Close
MiCon.Dispose() ' Pero puedo tambien utilizar su método Dispose
' Aqui, tengo los datos en MiDt ... ... ...
smtp = New SmtpClient(CBServidor.Text) ' Seleccion del Servidor SMTP (Choix du serveur smtp)
' ... ... ...
' Cuando no necesario este smtp :
smtp = Nothing ' El "Garbage Collector" hacá el resto
Mail.From = New MailAddress(Expedidor) ' Seleccion de un expedidor (Sélection de 1 expéditeur)
Mail.To.Add(New MailAddress(Destinatario)) ' Seleccion de un destinatario (Sélection de 1 destinataire)
' ... ... ...
Dim Attache As New Attachment(S)
Mail.Attachments.Add(Attache)
' ... ... ...
Mail.Dipose()
Imports System.Configuration
Public Class Conexion
Private Shared _connectionString As String
Public Shared ReadOnly Property ConnectionString As String
Get
If _connectionString Is Nothing Then
_connectionString = ConfigurationManager.ConnectionStrings("Calderas").ConnectionString
End If
Return Conexion._connectionString
End Get
End Propertyhttps://www.lawebdelprogramador.com/img/img.png?11.22
End Class
Private Sub UnProc( … )
Dim UnObjeto As UnTipoObjeto
UnObjeto = New UnTipoObjeto
‘ … los códigos del procedimiento
‘ Antes borrar :
UnObjet.Dispose()
En Sub