Soy muy nuevo en el enhebrado. Espero que alguien me pueda dar un ejemplo.Enhebrado WPF C#
Estoy tratando de iniciar un hilo cuando el usuario haga clic en el botón de inicio y haga lo siguiente proceso:
private void btnStart_Click(object sender, RoutedEventArgs e)
{
if (serialPort.IsOpen)
serialPort.Close();
try
{
//To set all the parameters for Serial Comm
serialPort.PortName = "COM14";
serialPort.BaudRate = int.Parse("38400");
serialPort.Parity = Parity.None;
serialPort.DataBits = 8;
serialPort.StopBits = StopBits.One;
serialPort.Encoding = System.Text.Encoding.ASCII;
serialPort.DataReceived += new SerialDataReceivedEventHandler(GotRawData);
serialPort.Open();
//To show that Com Port is Opened
txtboxOutput.AppendText(DateTime.Now.ToString("hh:mm:ss tt") + " - COM14 is opened." + Environment.NewLine);
txtboxOutput.ScrollToEnd();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
GotRawData private void() es un método en el que hacer algo para que algunos datos en bruto de una hardware.
Ver esta pregunta para obtener más información sobre la BackgroundWorker: http://stackoverflow.com/questions/5483565/how-to-use-wpf-background-worker –