Example #1
0
        public void Disconnect()
        {
            _state = 0;

            if (_connected)
            {
                _connected = false;
            }

            L2CAPAPI.L2CAPClosePSM(L2CAP_PSM_HIDP_INTR);
            L2CAPAPI.L2CAPClosePSM(L2CAP_PSM_HIDP_CTRL);

            if (0 != _cidCtrl)
            {
                L2CAPAPI.L2CAPCloseCID(_cidCtrl);
                _cidCtrl = 0;
            }
            if (0 != _cidIntr)
            {
                L2CAPAPI.L2CAPCloseCID(_cidIntr);
                _cidIntr = 0;
            }
            _bluetoothAddress = 0;

            if (null != Disconnected)
            {
                Disconnected(this, null);
            }

            if (null != _intrThread)
            {
                if (Thread.CurrentThread != _intrThread)
                {
                    _intrThread.Abort();
                }
            }
            if (null != _ctrlThread)
            {
                if (Thread.CurrentThread != _ctrlThread)
                {
                    _ctrlThread.Abort();
                }
            }
            lock (this)
            {
                if (null != _connectThread)
                {
                    _connectThread.Abort();
                    _connectThread = null;
                }
            }
        }