private void stopThreads() { // Cancel the thread that completed the connection if (_connectThread != null) { _connectThread.Cancel (); _connectThread = null; } // Cancel any thread currently running a connection if (_connectedThread != null) { _connectedThread.Cancel (); _connectedThread = null; } // Cancel the accept thread because we only want to connect to one device if (_acceptThread != null) { _acceptThread.Cancel (); _acceptThread = null; } _deviceAddress = string.Empty; }
//-------------------------------------------------------------- // THREAD METHODS //-------------------------------------------------------------- // Start the service of receiving. Specifically start AcceptThread to begin a // session in listening(server) mode. Called by the Activity onResume() public void Start() { lock (_locker) { #if DEBUG Log.Debug (Tag, "Start"); #endif // Cancel all the threads stopThreads(); // Start the thread to listen on a BluetoothServerSocket _acceptThread = new AcceptThread (this); if(_acceptThread.CanStart) { _acceptThread.Start (); setState (StateEnum.Listen); } else { setState(StateEnum.None); } } }