How do I access my form from a new thread?

Experts,

I have a button on my form which runs a new thread, and in this thread i'd like to update the main form controls.  Unfortunately I can't access Form.Control.Add, so I'm unsure how to get this working. I've added the code in a new thread as it causes the form to lock-up, because I'm running a while (true) loop.

Please help!
mhouldridgeAsked:
Who is Participating?
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
Only the main thread has access to the UI. Your thread will have to call back the main thread to do it.

Maybe you can use the BackGroundWorker component to simplify it: http://www.emoreau.com/Entries/Articles/2006/12/The-BackgroundWorker-component.aspx
0
 
rambovnCommented:
read this: Simple pattern to invoke GUI from another thread
http://kristofverbiest.blogspot.com/2007/02/simple-pattern-to-invoke-gui-from.html
0
 
Anurag ThakurConnect With a Mentor Technical ManagerCommented:
all the user interfacing functions needs to be performed from the main thread
http://www.yoda.arachsys.com/csharp/threads/winforms.shtml

you can use the background worker class as suggested emoreau to do operations
0
All Courses

From novice to tech pro — start learning today.