ehelin Posted June 13, 2006 Posted June 13, 2006 Hi: I am getting an out of memory exception from a combo box. I found a reference on the internet about this possibly occuring if the to string method of the objects contained in the combo box returning null. I have eliminated this possibility...and the error is still occurring. Anyone seen this? Eric Quote
Leaders snarfblam Posted June 13, 2006 Leaders Posted June 13, 2006 It can be a little difficult to diagnose the problem with only a very simple description of the symptoms. It would be best if you could provide some code, but you should at least give some sort of details (What are you putting in the ComboBox's collection? Does it happen every time? What do you get when you call the .ToString method? etc., etc., etc.). Quote [sIGPIC]e[/sIGPIC]
ehelin Posted June 14, 2006 Author Posted June 14, 2006 (edited) Here are the specifics Please bare with me...this post will be long with the error/code post. I will do the best formatting I can :) This is what I have so far: Reference to possible fix that I have ruled out (I think <grin!>)...this guy seemed to thing that the culprit might be the to tostring method returning a null value. http://www.hightechtalks.com/dotnet-framework-winforms-databinding/silly-outofmemoryexception-thrown-databound-combobox-225593.html Why do I think its ruled out? This is the error returned. The value returned by the tostring method is the pharmacy name and it has a name...in the error message, this value is "Pharm Name: COMAL DRUG," ======================== Start Error Msg ======================== Application Domain: MAInput.exe Assembly Codebase: file:///C:/Program Files/TMC/MAInput/MAInput.exe Assembly Full Name: MAInput, Version=1.0.2343.17411, Culture=neutral, PublicKeyToken=null Assembly Version: 1.0.2343.17411 Assembly Build Date: 6/1/2006 10:40:22 AM Exception Source: Exception Type: System.Exception Exception Message: Nested Catch Pharm null ptr error. ErrLine: 4, Pharm Name: COMAL DRUG, Pharm List Name: COMAL DRUG (New Braunfels) E. North St. & E. Garza St., Pharm Db Id: 337, Orig Ex: Too many items in the combo box. Exception Target Site: Object reference not set to an instance of an object. ======================== End Error Msg ======================== Offending Method - Please note that there is a lot of temporary code (i.e. ErrLine variable, nested try/catch stmts, etc.) I am using to try and track down the specific of what is happen...I don't usually wrap try catch stmts inside other try catch stmts :) According to my tests so far, the error being thrown starts at ErrLine 4. ======================== Start Code ======================== 'This method populates any previous visit's selected pharmacy if none is 'selected yet. Private Sub PopulatePrevPharm(ByVal pPrevPharm As Pharmacy) Dim PharmCmboCtr As Integer Dim PharmMatchFd As Boolean Dim Ctr As Integer Dim ErrLine As Integer = 1 'error code Dim CurPharm As Pharmacy 'error code Dim Ex2 As Exception 'error code Try '------------------------------------------------------------------------------ 'if a pharmacy was set in the previous visit, but one doesn't exist for this one, 'populate with the prev pharmacy and show as green. PharmCmboCtr = 0 PharmMatchFd = False ErrLine = 2 If Not pPrevPharm Is Nothing Then Try 'nested try/catch to locate bug 'cycle through the list and see if the one we are bring in is in the list For Each Pharm As Pharmacy In cmboDefaultPharmacy.Items ErrLine = 3 '--------------------------------------- CurPharm = Pharm ErrLine = 31 If Pharm.PharDBId = pPrevPharm.PharDBId Then ErrLine = 32 cmboDefaultPharmacy.SelectedIndex = PharmCmboCtr ErrLine = 33 cmboDefaultPharmacy.BackColor = Color.LightGreen ErrLine = 34 PharmMatchFd = True Exit For ErrLine = 35 End If PharmCmboCtr += 1 Next Catch ex As Exception 'log our elusive pharmacy null pointer exception. If ex.Message.IndexOf("Too many items in the combo box") <> -1 Then Ex2 = New Exception("1Nested Catch Pharm null ptr error. ErrLine: " + Convert.ToString(ErrLine) _ + ", Pharm Name: " + CurPharm.Name + ", Pharm List Name: " _ + CurPharm.ListName + ", Pharm Db Id: " + Convert.ToString(CurPharm.PharDBId) _ + ", Orig Ex: " + ex.message) Else Ex2 = New Exception("Nested Catch Pharm non-null ptr error. Orig Message: " + ex.message) End If LocalErrorLink.Error_Handler(Ex2) End Try ErrLine = 4 'if not in combo box, add Ctr = 0 If Not PharmMatchFd Then cmboDefaultPharmacy.Items.Add(pPrevPharm) ErrLine = 5 Try 'nested try/catch to locate bug For Each pharm As Pharmacy In cmboDefaultPharmacy.Items ErrLine = 6 CurPharm = Pharm If pharm.equals(pPrevPharm) Then cmboDefaultPharmacy.SelectedIndex = Ctr cmboDefaultPharmacy.BackColor = Color.LightGreen End If Ctr += 1 Next Catch ex As Exception 'log our elusive pharmacy null pointer exception. If ex.Message.IndexOf("Too many items in the combo box") <> -1 Then Ex2 = New Exception("2Nested Catch Pharm null ptr error. ErrLine: " + Convert.ToString(ErrLine) _ + ", Pharm Name: " + CurPharm.Name + ", Pharm List Name: " _ + CurPharm.ListName + ", Pharm Db Id: " + Convert.ToString(CurPharm.PharDBId) _ + ", Orig Ex: " + ex.message) Else Ex2 = New Exception("Nested Catch Pharm non-null ptr error. Orig Message: " + ex.message) End If LocalErrorLink.Error_Handler(Ex2) End Try ErrLine = 7 End If End If ErrLine = 8 cmboDefaultPharmacy.Sorted = True Catch ex As Exception 'log our elusive pharmacy null pointer exception. If ex.Message.IndexOf("Too many items in the combo box") <> -1 Then Ex2 = New Exception("3Nested Catch Pharm null ptr error. ErrLine: " + Convert.ToString(ErrLine) _ + ", Pharm Name: " + CurPharm.Name + ", Pharm List Name: " _ + CurPharm.ListName + ", Pharm Db Id: " + Convert.ToString(CurPharm.PharDBId) _ + ", Orig Ex: " + ex.message) LocalErrorLink.Error_Handler(Ex2) 'log as normal error Else LocalErrorLink.Error_Handler(ex) End If End Try End Sub ======================== Start Code ======================== Edited July 11, 2006 by PlausiblyDamp Quote
ehelin Posted July 11, 2006 Author Posted July 11, 2006 Think I found culprit Hi: I think I found the culprit...never mix setting up your GUI with another thread...all kinds of crazy things can happen :) If you have to, put all your GUI touching code in your thread's call back method...but the safer thing to do (anybody correct me if this is wrong) is to load your data and then populate your GUI once everything is loaded...controlling dependancies with boolean variables (i.e. test each thread to see if its loaded...something like "If ThreadComplete Then load that portion of my gui". My boss wants us to make our loads as fast as possible, so we multithread gathering data and as it comes in, we populate our GUI. There was one remote dependancy I thought I had taken care of...oops! Seems to be fixed now :) Thanks! Eric Quote
Administrators PlausiblyDamp Posted July 11, 2006 Administrators Posted July 11, 2006 If you are doing work in a background thread and need to update the UI you will need to get the main thread to 'Invoke' it, the InvokeRequired property should tell you if you need to do this. Search these forums and you should find a couple of mentions of this along with examples of the solution. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
ehelin Posted July 14, 2006 Author Posted July 14, 2006 Thanks! Thanks for the response! I did a look up on the forum, and found an example of this from Wile...who helped me in an email. Thanks for the help! Eric If you are doing work in a background thread and need to update the UI you will need to get the main thread to 'Invoke' it, the InvokeRequired property should tell you if you need to do this. Search these forums and you should find a couple of mentions of this along with examples of the solution. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.