C# lire seul port Série lorsque des données

Je veux lire mon port série, mais seulement lorsque les données proviennent(je veux pas d'interrogation).

C'est comment je le fais.

                Schnittstelle = new SerialPort("COM3");
                Schnittstelle.BaudRate = 115200;
                Schnittstelle.DataBits = 8;
                Schnittstelle.StopBits = StopBits.Two;
             ....

Puis-je commencer un thread

             beginn = new Thread(readCom);
             beginn.Start();

et dans mon readCom, je suis en train de lire en continu (interrogation 🙁 )

private void readCom()
    {

        try
        {
            while (Schnittstelle.IsOpen)
            {

                Dispatcher.BeginInvoke(new Action(() =>
                {

                    ComWindow.txtbCom.Text = ComWindow.txtbCom.Text + Environment.NewLine + Schnittstelle.ReadExisting();
                    ComWindow.txtbCom.ScrollToEnd();
                }));

                beginn.Join(10);

            }
        }
        catch (ThreadAbortException) 
        {

        }

        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

Je veux yout lire lorsqu'une Interruption est à venir. Mais comment puis-je le faire ?

OriginalL'auteur user2261524 | 2013-04-25