SerialPort を使用して換気システムと通信する af サーバーに接続する非同期関数を呼び出すと、問題が発生します。問題は、関数をゆっくりと呼び出すと、非常にうまく機能することです。Metro インターフェイスのボタンで。しかし、プログラムで10個のコマンドを次々に送信したい場合。例えば。Await Await ReadData("COMMAND")
The I/O operation has been aborted because of a thread exit or an application request (800703E3) エラーで失敗する10xしたがって、新しい関数が試行される前に関数が終了していないと思いますか?
私は次のように呼び出します:DataReceived = Await ReadData(SendCommand)
そして、それは関数を呼び出します
Public Shared Async Function SendReceive(SendCommand As String) As Task(Of String)
'Some code (try/catch) and so on.
Await _Socket.ConnectAsync(srvHostname, srvPort)
'Some more code (write to server that talks to ventilation system)
_writer.WriteString(SendCommand)
Await _writer.StoreAsync()
' More code (read answer from the server from the ventilation system)
Dim strReceivedBytes As String = Await _reader.LoadAsync(512)
Return _Reader.ReadString(strReceivedBytes)
End Function