Cross-thread operation not valid.

  • Thread starter Thread starter TClancey
  • Start date Start date
T

TClancey

I'm confused! Probably becuase I know little about threads, and really
should. But...

I have a serial port control, when it reads data I want to update several
things, database fields and tables, also a text box. Everything works fine
apart from updating the text box where I get this error.

I have other parts of code that update text boxes, list boxes all sorts of
controls that don't cause this error, even updating text boxes on other
forms!

I've come accross the mytxtbox.CheckForIllegalCrossThreadCalls = False
what are the potential problems using this? Bear in mind that the text
boxes are not editable and will only ever be updated every few seconds.

Any help greatfully recevied.
Cheers,
Tull.
 
VB2005 has made it where you can catch potiential hazards in creating cross
threads.

You are attempting to modify a control on a thread that is not the initial
thread making the control.

You can set 'CheckForIllegalCrossThreadCalls = False' which will solve he
problem. It is not safe to do because a third party program can access it.
If you feel safe in making this, then go for it.

I have created a splash form that is updated by a form. Since the splashform
only displays informaiton. I really don't care if a third part accesses the
control.

--
--
Thiele Enterprises - The Power Is In Your Hands Now!
--
I'm confused! Probably becuase I know little about threads, and really
should. But...

I have a serial port control, when it reads data I want to update several
things, database fields and tables, also a text box. Everything works fine
apart from updating the text box where I get this error.

I have other parts of code that update text boxes, list boxes all sorts of
controls that don't cause this error, even updating text boxes on other
forms!

I've come accross the mytxtbox.CheckForIllegalCrossThreadCalls = False
what are the potential problems using this? Bear in mind that the text
boxes are not editable and will only ever be updated every few seconds.

Any help greatfully recevied.
Cheers,
Tull.
 
Hi,

Download the terminal example from my homepage. It shows how to marshal
data from the DataReceived event (SerialPort receive thread context) to the
UI (STAThread context).

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
I'm very interested, can you please let me know which download I need?

Cheers,
Tull.
 
Back
Top