public override void Run()
            {
                if (Debug)
                {
                    Log.Debug(TAG, "BEGIN mAcceptThread " + this.ToString());
                }

                Name = "AcceptThread";
                BluetoothSocket socket = null;

                // Listen to the server socket if we're not connected
                while (_service._state != BluetoothActivityService.STATE_CONNECTED)
                {
                    try
                    {
                        // This is a blocking call and will only return on a
                        // successful connection or an exception
                        socket = mmServerSocket.Accept();
                    }
                    catch (Java.IO.IOException e)
                    {
                        Log.Error(TAG, "accept() failed", e);
                        break;
                    }

                    // If a connection was accepted
                    if (socket != null)
                    {
                        lock (this)
                        {
                            switch (_service._state)
                            {
                            case STATE_LISTEN:
                            case STATE_CONNECTING:
                                // Situation normal. Start the connected thread.
                                _service.Connected(socket, socket.RemoteDevice);
                                break;

                            case STATE_NONE:
                            case STATE_CONNECTED:
                                // Either not ready or already connected. Terminate new socket.
                                try
                                {
                                    socket.Close();
                                }
                                catch (Java.IO.IOException e)
                                {
                                    Log.Error(TAG, "Could not close unwanted socket", e);
                                }
                                break;
                            }
                        }
                    }
                }

                if (Debug)
                {
                    Log.Info(TAG, "END mAcceptThread");
                }
            }
            public override void Run()
            {
                Log.Info(TAG, "BEGIN mConnectThread");
                Name = "ConnectThread";

                // Always cancel discovery because it will slow down a connection
                _service._adapter.CancelDiscovery();

                // Make a connection to the BluetoothSocket
                try
                {
                    // This is a blocking call and will only return on a
                    // successful connection or an exception
                    mmSocket.Connect();
                }
                catch (Java.IO.IOException e)
                {
                    try
                    {
                        //var socket = (BluetoothSocket)device.getClass().getMethod("createRfcommSocket", new Class[] { int.class}).invoke(device,1);
                        //socket.connect();
                        //mmSocket = mmDevice.Class.GetMethod("createRfcommSocketToServiceRecord ", new Class[] { Java.Lang.Integer.Type }).Invoke(mmDevice, 1);
                        mmSocket = (BluetoothSocket)mmDevice.Class.GetMethod("createRfcommSocket", new Class[] { Java.Lang.Integer.Type }).Invoke(mmDevice, 1);
                        //mmSocket = mmDevice.CreateInsecureRfcommSocketToServiceRecord(MY_UUID);
                        mmSocket.Connect();
                    }
                    catch (Exception e2)
                    {
                        Log.Error(TAG, "Couldn't establish Bluetooth connection!");

                        _service.ConnectionFailed();

                        // Close the socket
                        try
                        {
                            mmSocket.Close();
                        }
                        catch (Java.IO.IOException e3)
                        {
                            Log.Error(TAG, "unable to close() socket during connection failure", e3);
                        }

                        // Start the service over to restart listening mode
                        _service.Start();
                        return;
                    }
                }

                // Reset the ConnectThread because we're done
                lock (this)
                {
                    _service.connectThread = null;
                }

                // Start the connected thread
                _service.Connected(mmSocket, mmDevice);
            }