当我调用连接到使用 SerialPort 与通风系统通信的 af 服务器的异步函数时,我遇到了问题。问题是,如果我慢慢调用该函数,它的工作非常好。通过 Metro 界面中的按钮。但是,如果我按程序想要一个接一个地发送 10 个命令。例如。10xAwait Await ReadData("COMMAND")
失败并出现错误 I/O 操作已因线程退出或应用程序请求(800703E3)而中止,因此我认为它在新功能尝试之前没有完成功能,我正确吗?
我打电话给: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