Skip to content

Instantly share code, notes, and snippets.

@tuanpmt
Created January 9, 2014 04:55
Show Gist options
  • Save tuanpmt/8329583 to your computer and use it in GitHub Desktop.
Save tuanpmt/8329583 to your computer and use it in GitHub Desktop.
HOW TO UPDATE UI FROM THREAD
public Form1()
{
InitializeComponent();
serialPort1.PortName = "COM2";
serialPort1.BaudRate = 9600;
serialPort1.Open();
Thread oThread = new Thread(new ThreadStart(recvThread));
oThread.Start();
}
private void recvThread()
{
while (true)
{
byte b = (byte)serialPort1.ReadByte(); /* wait a byte from COM port */
label1.Text = b.ToString(); /* error! */
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment