I need to update windows form controls data from Static method. we cannot access controls from static method because they are instance fields.then how to over come this.
private static void DataReceivedHandler(
object sender,
SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
lblID.Text = indata;
if (lstRFIDCards.Contains(indata))
{
lblIDValidationMes.Text = "ID Verified";
lblIDValidationMes.ForeColor = System.Drawing.Color.Green;
byte[] onBuffer = { 0XA5, 0XFF, 0X04, 0X57, 0X0F, 0X01, 0XF0, 0x0D, 0x0A };
sp.Write(onBuffer, 0, 9);
lblRelay.Text = "Relay ON";
lblRelay.ForeColor = System.Drawing.Color.Green;
Thread.Sleep(5000);
byte[] offbuffer = { 0xA5, 0xFF, 0x04, 0x57, 0x0F, 0x00, 0xF1, 0x0D, 0x0A };
sp.Write(offbuffer, 0, 9);
lblRelay.Text = "Relay OFF";
lblRelay.ForeColor = System.Drawing.Color.OrangeRed;
}
else
{
lblIDValidationMes.Text = "ID Not Matched Our Records.";
lblIDValidationMes.ForeColor = System.Drawing.Color.OrangeRed; ;
}
}