Exemple #1
0
        void ThreadAction()
        {
            // Set name of the thread.
            Thread.CurrentThread.Name = "RefreshAllThread";
            // DIrect input device querying and force feedback updated will run on a separate thread from MainForm therefore
            // separate windows form must be created on the same thread as the process which will access and update device.
            // detector.DetectorForm will be used to acquire devices.
            /// Main job of detector is to fire event on device connection (power on) and removal (power off).
            var manager  = new DirectInput();
            var detector = new DeviceDetector(false);

            do
            {
                // Sets the state of the event to non-signaled, causing threads to block.
                _ResetEvent.Reset();
                // Perform all updates if not suspended.
                if (!Suspended)
                {
                    RefreshAll(manager, detector);
                }
                // Blocks the current thread until the current WaitHandle receives a signal.
                // Thread will be release by the timer.
                // Do not wait longer than 50ms.
                _ResetEvent.WaitOne(50);
            }
            // Loop until suspended.
            while (_AllowThreadToRun);
            detector.Dispose();
            manager.Dispose();
        }
 public void UnInitDeviceDetector()
 {
     detector.DeviceChanged -= detector_DeviceChanged;
     detector.Dispose();
 }