M
Mo
I am trying to set a text box value when data is received from the com
port (barcode reader). I am getting the following error when I try to
set the text box TXNumber after data is received
Cross-thread operation not valid: Control 'TXNumber' accessed from a
thread other than the thread it was created on.
Any ideas how to work around this problem?
Thanks
Here is my code
________ Initialize Scanner _______________
public void Initialize_Scanner()
{
sp.BaudRate = 9600;
sp.Parity = Parity.None;
sp.DataBits = 8;
sp.StopBits = StopBits.One;
sp.ReadTimeout = 1500;
sp.DataReceived += new
SerialDataReceivedEventHandler(sp_DataReceived);
sp.Open();
}
________ Data Received? ______________
void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string ret = "\r";
string tempstring = sp.ReadLine().Replace(ret, "");
sp.Close();
this.TXNumber.Text = tempstring;
if (tempstring.Length> 0)
{
Run_process();
sp.Open();
}
}
port (barcode reader). I am getting the following error when I try to
set the text box TXNumber after data is received
Cross-thread operation not valid: Control 'TXNumber' accessed from a
thread other than the thread it was created on.
Any ideas how to work around this problem?
Thanks
Here is my code
________ Initialize Scanner _______________
public void Initialize_Scanner()
{
sp.BaudRate = 9600;
sp.Parity = Parity.None;
sp.DataBits = 8;
sp.StopBits = StopBits.One;
sp.ReadTimeout = 1500;
sp.DataReceived += new
SerialDataReceivedEventHandler(sp_DataReceived);
sp.Open();
}
________ Data Received? ______________
void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string ret = "\r";
string tempstring = sp.ReadLine().Replace(ret, "");
sp.Close();
this.TXNumber.Text = tempstring;
if (tempstring.Length> 0)
{
Run_process();
sp.Open();
}
}