我的应用程序有时会退出,没有任何异常。我在单独的线程中使用循环来读取HID设备。我认为问题就在那里。但是我不确定是什么原因导致了这个问题。我的代码有什么问题?
Private Sub USBListenServer()
If (readHandle IsNot Nothing) AndAlso (Not readHandle.IsInvalid) Then
Try
Dim dataBytes(&H40) As Byte
Dim bytesRead As Int32
Do
If (readHandle IsNot Nothing) AndAlso _
(Not readHandle.IsInvalid) AndAlso _
(Not readHandle.IsClosed) AndAlso _
HID_Read(hidHandle, readHandle, writeHandle, dataBytes, bytesRead) AndAlso _
(bytesRead > 0) Then
Dim myDataBytes(&H40) As Byte
Array.Resize(Of Byte)(myDataBytes, bytesRead - 1)
Array.Copy(dataBytes, 1, myDataBytes, 0, bytesRead - 1)
Dim _dataArrivedEvent As DataArrivedEventHandler = DataArrivedEvent
If _dataArrivedEvent IsNot Nothing Then
_dataArrivedEvent.Invoke(myDataBytes)
End If
End …Run Code Online (Sandbox Code Playgroud) vb.net ×1