Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Text box from thread

Status
Not open for further replies.

Kernowmarplek

Programmer
Jun 2, 2003
1
GB
I am building an application that sends and receives data from a laser coder. I am using multi-threading and would like to send the received string to a text box on the only form, however, the thread is unable to see the form.

For the code

static void ReadResponseThread()
{
StreamReader sr = new StreamReader(ss,System.Text.Encoding.ASCII);
try
{
for (;;)
{
string response = sr.ReadLine();
if (response != "")
{
txtBox1.Text = response;
}
}
}
catch(ThreadAbortException)
{
}
}

I get the following error

An object reference is required for the nonstatic field, method, or property 'WindowsSerial2.Form1.txtBox1'


Anybody know what's going on?
 
You should not attempt to access a GUI object from another thread directly. There was an article in either Visual Studio magazine or MSDN magazine a few months ago that tells how to do this safely.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top