Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I access my form from a new thread?

Posted on 2008-10-06
3
Medium Priority
?
1,085 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 900 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 600 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 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