Dictionary randomly loses content

FuZion

Well-known member
Joined
Jan 28, 2007
Messages
47
Programming Experience
Beginner
Hi there,

I'm using a Dictionary object to store the table names for db queries that I use, and different forms/objects reference this via a property on my main form. But, after a few data reads the table name begins to return nothing, and the count of my dictionary, previously 9, is zero. I'm not sure what causes this, because I don't clear the dictionary at any time. Is there any reason why this is happening.. would some code help?

Thanks!
 
This is what loads the dictionary data at form load
VB.NET:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Add MySQL Table Info
        my_tabs.Add("accts", "`jmif96_mfs`.`accounts`")
        my_tabs.Add("acctsNotes", "`jmif96_mfs`.`account_notes`")
        my_tabs.Add("invcs", "`jmif96_mfs`.`invoices`")
        my_tabs.Add("svcComments", "`jmif96_mfs`.`service_comments`")
        my_tabs.Add("svcInfo", "`jmif96_mfs`.`service_info`")
        my_tabs.Add("svcSheets", "`jmif96_mfs`.`service_sheets`")
        my_tabs.Add("trucks", "`jmif96_mfs`.`trucks`")
        my_tabs.Add("users", "`jmif96_mfs`.`users`")
        my_tabs.Add("userPerms", "`jmif96_mfs`.`user_perms`")
    End Sub

And this is the property that accesses it

VB.NET:
    Public ReadOnly Property mtab(ByVal tname As String) As String
        Get
            Return my_tabs.Item(tname)
        End Get
    End Property

Hope this helps!
 
Dicts dont just lose content. Either youre swapping it out for another dictionary, or youre calling clear. Right click on mtabs and Find All References to it. Put a breakpoint on every one and run your process, eventually you'll break on the line that is clearing or renewing your dictionary, then you can look at the call stack to find out how it got there
 
They don't.. the point it was losing content was within a separate thread, thus it was unable to access the dictionary and it would return a count of 0 when debugging. All fixed now, thanks for your help!
 
Back
Top