public override void Run() { service.btAdapter.CancelDiscovery(); try { socket.Connect(); } catch (Exception) { try { socket.Close(); } catch (Exception e2) { Toast.MakeText(Application.Context, "Unable to Close Socket due to " + e2.Message, ToastLength.Long).Show(); } service.ConnectionFailed(); return; } lock (this) { service.connectThread = null; } service.Connected(socket, device); }
public override void Run() { BluetoothSocket socket = null; while (service.GetState() != ConnectionState.Connected) { try { socket = serverSocket.Accept(); } catch (Exception e) { Toast.MakeText(Application.Context, "Accept Failed due to " + e.Message, ToastLength.Long).Show(); break; } if (socket != null) { lock (this) { switch (service.GetState()) { case ConnectionState.Listen: case ConnectionState.Connecting: service.Connected(socket, socket.RemoteDevice); break; case ConnectionState.None: case ConnectionState.Connected: try { socket.Close(); } catch (Exception e) { Toast.MakeText(Application.Context, "Could not close socket due to " + e.Message, ToastLength.Long).Show(); } break; } } } } }