Results 1 to 5 of 5

Thread: how to remove an object that was created, dispose?!

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Posts
    61

    how to remove an object that was created, dispose?!

    In a program i made , an object is created during runtime, this object uses a timer inside( of its own ), when i dispose my object, the programs shows an error because the timer inside of it was still working .
    why does this happen? when you dispose an object doesnt it dispose and kill everything that the object contains?!!

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Well , simply just call Dispose Property of that object like so :

    VB Code:
    1. Dim ad As New OleDb.OleDbDataAdapter()
    2.  
    3. 'When you are done , do this to free up
    4. ad.Dispose()
    I don't know about your code but it seems you're doing some bad coding practice .
    Last edited by Pirate; Apr 19th, 2003 at 11:55 AM.

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    To have more elegant code , it highly recommended to include your unwanted resources in the Form's Dispose Method which looks similar to this one :

    VB Code:
    1. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    2.         If disposing Then
    3.             If Not (components Is Nothing) Then
    4. 'Add this line and pass the object you want to dispose .
    5.  
    6.                 components.Add(A)
    7.                 components.Dispose()
    8.             End If
    9.         End If
    10.         MyBase.Dispose(disposing)
    11.     End Sub

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    The timer is executing on a different thread, so in your dispose method, make sure you stop the timer.

  5. #5
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    haj-agha, what object are you talking about anyways
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width