selectednode in Treeview lost when accessed by spawned Thread

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I am trying to spawn a sunroutine in a worker thread for populating a
trreeview. I set the selectednode and then start the thread. However, the
thread errors because the selectednode was found to equal "Nothing".

Is there some kind of trick to get the threaded subroutine to see the
selectednode to process?

Thank you inadvance for any assistance.

Dean.
 
Dean,

You can't access a form or control from a thread other than the main UI
thread. That doesn't mean you can't take advantage of threads though.
What I would do is use my worker thread to retrieve the list of items
from the database or whatever and place them in some type of collection
and then call Control.BeginInvoke at the end of the worker thread to
marshal the execution of a delegate onto the UI thread. That delegate
would build the treeview from the collection you just populated.

The following is an excellent introduction to using threads in Windows
forms.

<http://www.yoda.arachsys.com/csharp/threads/winforms.shtml>

Brian
 
Back
Top