public static void ReadUSBWorker(object data) { XboxReader reader = ((XboxReader)data); while (!reader.inShutdown) { USBPacket packet = reader.packetPool[reader.currentPacketInPool]; reader.currentPacketInPool += 1; reader.currentPacketInPool %= 100; uint status = 0; uint events = 0; ulong timeSop = 0; ulong timeDuration = 0; uint timeDataOffset = 0; packet.Length = BeagleApi.bg_usb2_read( ((XboxReader)data).hBeagle, ref status, ref events, ref timeSop, ref timeDuration, ref timeDataOffset, 1024, packet.Packet); if (packet.Length == 23 && (packet.Packet[0] == BeagleApi.BG_USB_PID_DATA1 || packet.Packet[0] == BeagleApi.BG_USB_PID_DATA0) && packet.Packet[1] == 0x00 && packet.Packet[2] == 0x14) { reader.packetsToBeProcessed.Enqueue(packet); } } }