Solved

How do I access my form from a new thread?

Posted on 2008-10-06
3
1,076 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 69

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now