2013-10-31 8 views
0

환기 시스템과 통신하기 위해 SerialPort를 사용하는 af 서버에 연결하는 비동기 함수를 호출 할 때 문제가 있습니다. 문제는 함수를 천천히 호출하면 매우 잘 작동한다는 것입니다. Metro 인터페이스의 버튼으로. 그러나 만약 내가 프로그래밍 방식으로 서로 10 개의 명령을 보내길 원한다면. 예. 10x Await Await ReadData("COMMAND") 오류로 실패 스레드 종료 또는 응용 프로그램 요청 (800703E3)으로 인해 I/O 작업이 중단되었습니다. 따라서 새 기능이 제대로 작동하기 전에 함수가 완료되지 않았다고 생각합니까?기다리는 방법 기다리는 방법

나는 콜 : DataReceived = Await ReadData(SendCommand)

그리고 내가 함수가 끝나기 전에 여러 번 클릭 할 때 문제는 accouring되는 함수 어떻게 든

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

를 호출합니다. 그래서 해결책은 기능이 존재할 때까지 버튼을 비활성화하는 것입니다.