I have a big problem and I hope you will give me support.
Class A is a windows form containing a listbox. A method of this class A starts a thread, which is responsible for loading of a very huch amount of data lines. These lines have to be added in realtime to the listbox of Class A. The functionality of this thread is implemented in a class B.
The difference to the MSDN example is: In class B the lines to be added to the listbox of class A are gathered and an array of ap. 1000 lines is sent to the listbox of class A via the delegate method. After that the thread pauses for 500 milliseconds. In the meanwhile the delegate method processes this data array and adds the array items to the listbox.
And now trouble comes into paradise:
In some cases my coding runs into an exception: The invoke of the delegate method to fill the listbox of class A doesn’t work. The exception message is (translated): “The value may not be NULL. Name of the parameter: item.”
(I get the german message: „Der Wert darf nicht NULL sein. Parametername: item”.)
System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object args, Boolean synchronous)
System.Windows.Forms.Control.Invoke(Delegate method, Object args)
and so on…..
Could it be a runtime topic?????????? This is my assumption, but without ideas whether I’m right or not and how to solve the problem:
The main thread (class A) is adding 1000 items to the listbox and the thread running in class B calls the delegate method of class A to add the next 1000 items in this period of time. The delegate method is called to fill the listbox again while the delegate method from the call before is just working.
Do you have an idea how to get rid of this problem?
You are great! With your advise I could fix the bug! During parsing of very large files I added the file contents into an array and called the delegate function to add the array items into a listbox control.
This array contained some “null” items I couldn’t identify up to now, because the array is very large and I was really blind to see the horrible array item with the content “null”!!!!!
I was too stupid to understand the meaning of the exception message and looked for runtime problems, but with your expertise I could learn a lot and could fix the bug! Thanks! Now I have to debug my SW to find the situation where an array item with “null” content is added...
At the moment a quick and dirty workaround inside the delegate method avoids the exception and all is working fine :-)
I am glad that I could be of help. You have no idea how much help I have gotten from "gurus" in the past. After going on 15 years of reading error messages I can nail one everyonce in a while, you will get there too with time.