>I am currently using Florian Leitner's
HID USB library in my VB.NET solution for communicating with a pin pad. As per his sample code, I set up an event handler to handle incoming responses from the device which are stored in an ArrayList called usbBuffer:
>
>
> Private Sub BufferEventHandler(ByVal sender As Object, ByVal e As System.EventArgs)
>
> If USBInterface.usbBuffer.Count > 0 Then
>
> While USBInterface.usbBuffer(0) Is Nothing
>
> SyncLock USBInterface.usbBuffer.SyncRoot
>
> USBInterface.usbBuffer.RemoveAt(0)
>
> End SyncLock
>
> End While
>
> _receiveArray = CType(USBInterface.usbBuffer(0), Byte())
>
> _usbInterface.stopRead()
>
> SyncLock USBInterface.usbBuffer.SyncRoot
>
> USBInterface.usbBuffer.RemoveAt(0)
>
> End SyncLock
>
> End If
>
> End Sub
>
>
>The problem is that the RemoveAt is not working, since the first element in the list remains there after the handler is done. Could someone please advise as to what I've done wrong, or perhaps use a different approach?
Which RemoveAt() doesn't work - presumably not the one contained in the While...EndWhile because that would leave you in an endless loop?
Are you *sure* that the RemoveAt() after reading the content doesn't work - is it possible that a new one is added immediately after the lock is released ?