Listbox.Clear not clearing
Posted on 2008-11-04
I have a form with a button and a listbox.
When the button is clicked, it calls Listbox.Clear, and then fires off a new thread.
That thread, via an event (processing code which is on the form class) inserts items in the list.
I then click the button again, stick a breakpoint on List.Clear(), after its called the Count property gets set to 0, however the "entries" field (found inside "items") is still populated with all the objects I added. As a result the second time round I duplicate the entries in the listbox.
I've tried calling Listbox.Refresh/Update all over the place, also using Listbox.Invoke to add the item on the same thread (dispite requires invoke returning false). I'm very confused.
I don't kill/abort the thread at any point, just let it run to the end of the method in its threadstart. When the button is clicked again, a new instance of the thread is created, which then runs.
Thanks in advance.