My code is here:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace AVR_to_RS232
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
textBox1.Text = serialPort1.ReadExisting();
}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.Open();
}
}
}
But in "serialPort1_DataReceived" event I can't insert "textBox1.Text = serialPort1.ReadExisting();" because the program display an error. Here is the error:
"Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on."
What can i do.
MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!
This post has been edited by JackOfAllTrades: 18 March 2012 - 03:49 AM

New Topic/Question
Reply



MultiQuote




|