/// <summary>
        /// Starts vibration on the device.
        /// </summary>
        /// <param name="duration">A <see cref="TimeSpan"/> object specifying the amount of time for which the phone vibrates.</param>
        /// <exception cref="ArgumentOutOfRangeException">Duration is greater than the maximum allowed duration or duration is negative.</exception>
        public void Start(System.TimeSpan duration)
        {
            if (duration.CompareTo(MaximumDuration) > 0)
            {
                throw new ArgumentOutOfRangeException("duration", Phone.Properties.Resources.vibratecontroller_DurationMax);
            }

            if (duration.Ticks < 0)
            {
                throw new ArgumentOutOfRangeException("duration", Phone.Properties.Resources.vibratecontroller_DurationMin);
            }

            if (InTheHand.WindowsCE.Forms.SystemSettingsInTheHand.Platform == WinCEPlatform.Smartphone)
            {
                int hresult = NativeMethods.Vibrate(0, IntPtr.Zero, true, (int)duration.TotalMilliseconds);
                if (hresult < 0)
                {
                    Marshal.ThrowExceptionForHR(hresult);
                }
            }
            else if (InTheHand.WindowsCE.Forms.SystemSettingsInTheHand.Platform == WinCEPlatform.PocketPC)
            {
                if (ledIndex > -1)
                {
                    NativeMethods.NLED_SETTINGS_INFO nsi = new NativeMethods.NLED_SETTINGS_INFO();
                    nsi.LedNum     = ledIndex;
                    nsi.OffOnBlink = 1;
                    bool success = NativeMethods.NLedSetDevice(2, ref nsi);

                    // setup a thread to turn off after duration
                    System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(TurnOffLed), (int)duration.TotalMilliseconds);
                }
            }
        }
 private void TurnOffLed(object duration)
 {
     System.Threading.Thread.Sleep((int)duration);
     NativeMethods.NLED_SETTINGS_INFO nsi = new NativeMethods.NLED_SETTINGS_INFO();
     nsi.LedNum     = ledIndex;
     nsi.OffOnBlink = 0;
     bool success = NativeMethods.NLedSetDevice(2, ref nsi);
 }