Solved

How do I access my form from a new thread?

Posted on 2008-10-06
3
1,077 Views
Last Modified: 2012-05-05
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!
0
Comment
Question by:mhouldridge
3 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 300 total points
ID: 22649276
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
 
LVL 8

Expert Comment

by:rambovn
ID: 22649509
read this: Simple pattern to invoke GUI from another thread
http://kristofverbiest.blogspot.com/2007/02/simple-pattern-to-invoke-gui-from.html
0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 200 total points
ID: 22655585
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

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question