|
-
June 29th, 2010, 12:41 PM
#1
Problems with Threads and Invokes
Dear C#-experts!
I have a big problem and I hope you will give me support.
My problem:
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.
I implemented a delegate method to fill the listbox (owned by class A) via class B.
I did it like the MSDN proposes: --> http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx
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”.)
Stack trace:
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:
Assumption:
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?
Thanks a lot in advance!!!
Paula
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|