unsafe void ReadThread() { if (!HandleAcquire()) { return; } _readRunLoop = NativeMethods.CFRunLoopGetCurrent(); try { var inputCallback = new NativeMethods.IOHIDReportCallback(ReadThreadCallback); var removalCallback = new NativeMethods.IOHIDCallback(RemovalCallback); byte[] inputReport = new byte[Device.GetMaxInputReportLength()]; fixed(byte *inputReportBytes = inputReport) { NativeMethods.IOHIDDeviceRegisterInputReportCallback(_handle, (IntPtr)inputReportBytes, (IntPtr)inputReport.Length, inputCallback, IntPtr.Zero); NativeMethods.IOHIDDeviceRegisterRemovalCallback(_handle, removalCallback, IntPtr.Zero); NativeMethods.IOHIDDeviceScheduleWithRunLoop(_handle, _readRunLoop, NativeMethods.kCFRunLoopDefaultMode); NativeMethods.CFRunLoopRun(); NativeMethods.IOHIDDeviceUnscheduleFromRunLoop(_handle, _readRunLoop, NativeMethods.kCFRunLoopDefaultMode); } GC.KeepAlive(this); GC.KeepAlive(inputCallback); GC.KeepAlive(removalCallback); GC.KeepAlive(_inputQueue); } finally { HandleRelease(); } }
unsafe void ReadThread() { if (!HandleAcquire()) { return; } _readRunLoop = NativeMethods.CFRunLoopGetCurrent(); try { var callback = new NativeMethods.IOHIDReportCallback(ReadThreadCallback); byte[] inputReport = new byte[_device.MaxInputReportLength]; fixed (byte* inputReportBytes = inputReport) { NativeMethods.IOHIDDeviceRegisterInputReportCallback(_handle, (IntPtr)inputReportBytes, (IntPtr)inputReport.Length, callback, IntPtr.Zero); NativeMethods.IOHIDDeviceScheduleWithRunLoop(_handle, _readRunLoop, NativeMethods.kCFRunLoopDefaultMode); NativeMethods.CFRunLoopRun(); NativeMethods.IOHIDDeviceUnscheduleFromRunLoop(_handle, _readRunLoop, NativeMethods.kCFRunLoopDefaultMode); } GC.KeepAlive(this); GC.KeepAlive(callback); GC.KeepAlive(_inputQueue); } finally { HandleRelease(); } }