Solved

How do I access my form from a new thread?

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

759 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