private async void send_Click(object sender, EventArgs e)
{
data = "1234567890";
try
{
serialPort1.WriteLine(data);
MessageBox.Show(data);
}
catch (InvalidOperationException)
{
MessageBox.Show("COM Port is not available");
}
await PeriodicDataSendAsync();
}
private async Task PeriodicDataSendAsync()
{
await Task.Run(() =>
{
while (true)
{
Thread.Sleep(5000);
try
{
serialPort1.WriteLine(data);
MessageBox.Show(data);
}
catch (InvalidOperationException)
{
MessageBox.Show("COM Port is not available");
}
}
});
}