I have a problem with my C# Windows Form App, i'm trying to change the active tab in tabControl1, it works when I click on the button1 but when I send serial data, the page change, but the program crashes.
The serial data is sent by an Arduino, it only send "S" every 2 seconds.
Here is the code I used to test this :
public partial class Form1 : Form
{
int page = 0;
public Form1()
{
InitializeComponent();
serialPort1.Open();
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
page++;
if (page == 4)
{
page = 0;
}
tabControl1.SelectedIndex = page;
tabControl1.Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
page++;
if (page == 4)
{
page = 0;
}
tabControl1.SelectedIndex = page;
tabControl1.Refresh();
}
}
Is this a bug, or am I doing it the wrong way ?