Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To: Auto Dispose a Custom Control?
Message
De
23/02/2007 14:20:14
 
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:
01198419
Vues:
15
Ben,

I was in the middle of replying to this when you posted your workaround.

My point in asking the questions I asked was that I'm pretty sure that all you really needed to do was override the UserControl's Dispose method (you don't need the Implements IDisposable in your class, since UserControl is already IDisposable). Then clsExamSelection.Dispose() method gets called as the Form disposes of it's contained controls and itself. Your clsExamSelection.Dispose() method would only contain two statements: the Me.PrivateDataSet_Destroy() and the base.Dispose(disposing).

~~Bonnie




>>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
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform