Lets say I want to receive some data from the serial port. Using a block call for serial.ReadLine() and using the following event.
private void port_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
var port = (SerialPort)sender;
string line = port.ReadLine();
// PROCESS DATA Somewhere else
}
I was reading from different sources and all of they say that the serial.ReadLine has its own thread and I should not modify the UI from this thread unless using BeginInvoke. However, I notice that during some time the UI will become unresponsive anyway.
So here is my question. Calling a new thread inside port_DataReceived will be a bad idea? I want to receive the data and process the received data in another thread however mythread.Start() where to put it? I cannot be starting it all the time I just want it to know somehow when to run independently after receiving the data. And according to MSDN a aborted thread cannot be started again. Putting Thread.Sleep is freezing my UI.