GUI Multithreading Woes
Date: 12/13/07
(C Sharp) Keywords: no keywords
I'm new at this topic so please be nice. :)
I need your help.
I have two code files; one contains a standard derived windows form and the other file contains a class that "does stuff". The first class (the main form) contains a listbox that I want the second class to be able to access. Without using any multithreading the only way I can access this listbox in the second class is to pass a reference to the constructor of the second class, regardless of the access modifier of the listbox. For some reason this doesn't feel right. Please clarify this first.
Next consider the main form creating an instance of the second class in a separate thread. This would involve delegates (I believe) to be able to update the main form's listbox safely from the second class. Is the delegate defined in the second class or the form class?
Here's some pseudocode:
(form class, file 1)
form has a listbox
create object of class 2 in its own thread
run thread until finished
(class 2, file 2)
do stuff
write status info back to the listbox in the first class as the object processes
How do I go about doing this? DOES the listbox reference need to be passed to the second class? I'd like to keep the two classes in separate files if possible.
Thanks in advance.
Source: http://community.livejournal.com/csharp/89458.html