Welcome to Dream.In.Code
Become a C# Expert!

Join 150,394 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,034 people online right now. Registration is fast and FREE... Join Now!




Changing label1.text in MainForm from a thread

 
Reply to this topicStart new topic

Changing label1.text in MainForm from a thread, Using a thread to update a text on a label in some other thread.

martinSc#ei
10 Mar, 2008 - 06:49 AM
Post #1

New D.I.C Head
*

Joined: 10 Mar, 2008
Posts: 2

In my program i have one thread besides the main thread.

This thread(not main) reads from a database;while it does that i want a label i my MainForm to display
the status.
When i try to compile the program it says that "Label1 is not an object in the current context" or something
similar.
Isn't it supposed to be possible to share data among threads?
Can't objects in the mainform only be manipulated thru the main thread?

I have tried the stuff i figured out myself could be wrong without success.

Any suggestions?
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Changing Label1.text In MainForm From A Thread
10 Mar, 2008 - 06:53 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You cannot update a UI control from outside the thread which created the control. You can, however, marshal the call, using a delegate, onto the thread which did create the control and update it that way. It's explained more in this tutorial on Cross thread communication in C#. Happy reading smile.gif
User is online!Profile CardPM
+Quote Post

martinSc#ei
RE: Changing Label1.text In MainForm From A Thread
10 Mar, 2008 - 07:22 AM
Post #3

New D.I.C Head
*

Joined: 10 Mar, 2008
Posts: 2

QUOTE(PsychoCoder @ 10 Mar, 2008 - 07:53 AM) *

You cannot update a UI control from outside the thread which created the control. You can, however, marshal the call, using a delegate, onto the thread which did create the control and update it that way. It's explained more in this tutorial on Cross thread communication in C#. Happy reading smile.gif

THANKS!
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Changing Label1.text In MainForm From A Thread
10 Mar, 2008 - 07:26 AM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Anytime, glad I could help smile.gif
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 06:10PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month