IOHIDDeviceUnscheduleFromRunLoop() private method

private IOHIDDeviceUnscheduleFromRunLoop ( IntPtr device, IntPtr runLoop, IntPtr runLoopMode ) : void
device System.IntPtr
runLoop System.IntPtr
runLoopMode System.IntPtr
return void
Example #1
0
        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();
            }
        }