2014-02-05 2 views
-1

프로그램을 정지시키는 이러한 오류를 처리 할 수 ​​없습니다.Visual Studio에서 예외 처리

어떻게 처리할까요? 이 내 디버거 출력 :

A first chance exception of type 'System.IO.IOException' occurred in System.dll 
A first chance exception of type 'System.InvalidOperationException' occurred in System.dll 
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll 
A first chance exception of type 'System.TimeoutException' occurred in System.dll 
A first chance exception of type 'System.IO.IOException' occurred in System.dll 

내가

Try 
    Dim str As String = SerialPort.ReadLine() 
Catch ex As Exception 
    MsgBox(ex) 
End Try 

하지만 여전히 프로그램 동결을 사용!

+2

이는 처음 예외이며 무시해야합니다. 그들은 당신의 프로그램이 멈추게하지 않습니다. –

+0

읽을 내용이 없으면 어떻게 될까요? –

+0

첫 번째 기회 예외 알림 수신 (http://msdn.microsoft.com/en-us/library/dd997368%28v=vs.110%29.aspx)하지만 John 그들은 당신의 프로그램이 멈추는 원인이되지 않는다고 말한다. SerialPort가 제대로 초기화되지 않은 것 같다. – vzamanillo

답변

1

ReadLine 메서드는 읽기가 완료 될 때까지 프로그램을 차단합니다.

당신이처럼 DataReceived 이벤트를 사용한다 : 오픈 물론

Public WithEvents serial As New SerialPort("COM1") 
Public Sub serial_OnDataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles serial.DataReceived 
    MsgBox(e.ToString) 
End Sub 

() 당신하여 SerialPort)

편집 :

당신이 정말로()에서는 ReadLine를 사용하려는 경우, 제한 시간을 설정하려고 시도하십시오 :

Try 
    SerialPort.ReadTimeout = 1000 
    Dim str As String = SerialPort.ReadLine() 
Catch ex As Exception 
    MsgBox(ex) 
End Try 

독서를 중단해야하지만, 이미 프로를 경험 했어야합니다. 이런 식으로 쉰다.