Stop Stream.BeginRead()

前端 未结 3 1536
旧时难觅i
旧时难觅i 2021-01-19 03:38

i need to read data from my virtual com port and detect the message \"Dreq\". Once i press the connect button, it connects to my COM8 port and begins reading in a new thread

3条回答
  •  借酒劲吻你
    2021-01-19 04:17

    You can try calling sp.DiscardOutBuffer(). It will call your read callback and you can then use stream.EndRead().

    private void disconnectButton_Click(object sender, EventArgs e)
    {
        sp.DiscardOutBuffer();
        stream.EndRead(recv_result);
        sp.Close();
    }
    

提交回复
热议问题