CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Dispose of dictionary

  1. #1
    Join Date
    Nov 2012

    Dispose of dictionary

    Hi all!

    I have a dictionary that I am using for a program and I would like to be able to close the dictionary without closing the form.

    I have tried unload, dispose and everything I can think of.

    The data is displayed in a listbox and a textbox. I can clear these but, of course, it doesn't release all of the variables. So if I try to reload the file I get a key already exists message.

    So, is there any way to close the form data and release all of the key/value pairs?


  2. #2
    Join Date
    Jun 2005
    JHB South Africa

    Re: Dispose of dictionary

    Show some code of how your assigning these variables and the dictionary.. maybe there's something not quite right there...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  3. #3
    Join Date
    Jul 2001
    Sunny South Africa

    Re: Dispose of dictionary

    Have you tried DictionaryObject.Clear before the call to Dispose it?

  4. #4
    Join Date
    Nov 2012

    Re: Dispose of dictionary

    Thanks for the replies!

    If I try to clear then dispose it exits the app and that is not what I am trying to do......

    The code that I am using to create the dict is pretty straightforward.

    'Open File
        Private Sub btnOpen_Click(ByVal sender As System.Object, _
       ByVal e As System.EventArgs) Handles btnOpen.Click
            If c4wFile.ShowDialog() = Windows.Forms.DialogResult.OK Then
                srFileReader = System.IO.File.OpenText(c4wFile.FileName)
                strLast = srFileReader.ReadLine()
                Do Until strLast = ""
                    SplitSTR = Split(strLast, "|")
                    dict.Add(SplitSTR(0), SplitSTR(1))
                    strLast = srFileReader.ReadLine()
            End If
        End Sub
    I am just having a problem closing the file for some reason.

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)