This may be a stupid question because I am new to C# but I am trying to send a signal using the serial port in a single send mode, and a continuous mode. I have a check box to indicate the send mode. When I click on the check box and click send, the application gets stuck in an infinite loop and I lose control of the application.
private void bSend_Click(object sender, EventArgs e)
{
byte[] Break = new byte[1] { 0x00 };
string input = tbTX.Text;
byte[] bytesToSend = input.Split().Select(s => Convert.ToByte(s, 16)).ToArray();
while (cbContinuous.Checked) // Checkbox named continuous
{
// Generate Break and MAB signal
headerSignal();
// Set back to DMX timing
DMXSettings();
mySerialPort.Write(bytesToSend, 0, bytesToSend.Length);
}
// Generate Break and MAB signal
headerSignal();
// Set back to DMX timing
DMXSettings();
mySerialPort.Write(bytesToSend, 0, bytesToSend.Length);
}
Is there any way I can un-check the check box while it is in the infinite loop to regain control and stop sending? Or is there a better way that I can do this?