Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To: Auto Dispose a Custom Control?
Message
 
À
23/02/2007 12:06:27
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01198325
Message ID:
01198389
Vues:
11
>How did you create the custom control? Is it sub-classed from UserControl? It probably should be if it's not. And how did you create the dispose method? Did you override the base class Dispose?

Here is my (Hidden) Class Signature:
Partial Class clsExamSelection
    Inherits System.Windows.Forms.UserControl
.
.
.
End Class
Here is my visible Class code:
Public Class clsExamSelection : Implements IDisposable

    Public Overloads Sub Dispose()
        '************************************************************************
        ' Procedure/Function: Dispose()
        ' Author: Ben Santiago
        ' Last Revision: 02/23/2007
        ' Description:
        '       Disposes of internal resources (if any) and prevents the Finalize
        '       routine from running so that the GarbageCollector doesn't attempt
        '       to dispose this object again.
        '************************************************************************

        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub

    Protected Overridable Overloads Sub Dispose(ByVal Disposing As Boolean)
        '************************************************************************
        ' Procedure/Function: Dispose()
        ' Author: Ben Santiago
        ' Last Revision: 02/23/2007
        ' Description:
        '       Manually disposes additional objects if needed.
        '************************************************************************

        Try
            If Disposing Then
                '***************************************
                ' Dispose Of Individual Components
                '***************************************
                If components IsNot Nothing Then
                    components.Dispose()
                End If
            End If

            '***************************************
            ' Remove Private DataSet
            '***************************************
            MessageBox.Show("Removing DataSet")
            Me.PrivateDataSet_Destroy()
        Finally
            '***************************************
            ' Call Base Dispose Method
            '***************************************
            MyBase.Dispose(Disposing)
        End Try
    End Sub

    Protected Overrides Sub Finalize()
        '************************************************************************
        ' Procedure/Function: Finalize()
        ' Author: Ben Santiago
        ' Last Revision: 02/23/2007
        ' Description:
        '       Auto dispose this object when nothing references this object, 
        '       using Garbage Collection.
        '************************************************************************

        Dispose(False)
    End Sub

End Class
________________________
Ben Santiago, MCP & A+
Programmer Analyst (SQL, FoxPro, VB, VB.Net, Java, HTML, ASP, JSP, VBS)
Eastern Suffolk BOCES - Student Data Services


Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-Rich Cook
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform