Does the text box get its' text set in the data received event? You should also call .Invoke from the Textbox and not the form since that is the control you are manipulating.
private SerialPort port;
public frmInvoke()
{
InitializeComponent();
}
private void frmInvoke_Load(object sender, EventArgs e)
{
port = new SerialPort();
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
}
void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SetMessageText(port.ReadExisting());
}
public delegate void SetText(string s);
public void SetMessageText(string s)
{
if (textBox1.InvokeRequired)
{
textBox1.Invoke(new SetText(SetMessageText), s);
}
else
{
textBox1.Text = s;
}
}
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
So is the timer never raising the Tick event? Or are you getting an exception? I just tried starting the timer in another thread and it doesn't throw an error but it doesn't work either.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
OK, replace your timer1.Enabled line with this:
this.Invoke(new MethodInvoker(
delegate()
{
this.timer1.Start();
}));
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735