2013-10-31 101 views
0

我有一個問題,當我調用連接到使用SerialPort與通風系統通信的af服務器的異步功能時。問題是,如果我慢慢地打電話,它的工作非常好。通過Metro界面中的按鈕。但是,如果我編程想要發送10個命令後對方。例如。 10x Await 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 

回答

0

不知怎的,當我的函數結束前多次點擊的問題只會accouring。所以解決方案是禁用按鈕,直到功能存在。