Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can't figure out why ArrayList.RemoveAt() is not working
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2008 Server
Application:
Desktop
Miscellaneous
Thread ID:
01519460
Message ID:
01519494
Views:
26
>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 ?
Previous
Reply
Map
View

Click here to load this message in the networking platform