private void ThreadRun()
        {
            byte[] lenbuffer = new byte[2];

            while (true)
            {
                try
                {
                    byte[] d;
                    if (_sendData.TryDequeue(out d))
                    {
                        NetworkDataTools.SetUInt16(out lenbuffer[0], out lenbuffer[1], (ushort)d.Length);
                        mmOutStream.Write(lenbuffer, 0, 2);
                        mmOutStream.Write(d, 0, d.Length);
                    }
                    else
                    {
                        Thread.Sleep(0);
                    }
                }
                catch (Java.IO.IOException e)
                {
                    SAMLog.Warning("ABTA::ThreadSend_ConnLost", e.Message);
                    _adapter.ThreadMessage_ConnectionLost();
                    break;
                }
            }
        }
        private void ThreadRun()
        {
            byte[] buffer = new byte[SAMNetworkConnection.MAX_PACKAGE_SIZE_BYTES * 3];

            ushort currentLen    = 0;
            int    currentOffset = 0;

            // Keep listening to the InputStream while connected
            while (true)
            {
                try
                {
                    // Read from the InputStream
                    var bytes = mmInStream.Read(buffer, currentOffset, SAMNetworkConnection.MAX_PACKAGE_SIZE_BYTES);

                    if (currentLen == 0)
                    {
                        if (bytes >= 2)
                        {
                            currentLen = NetworkDataTools.GetUInt16(buffer[0], buffer[1]);
                            if (currentLen == 0)
                            {
                                SAMLog.Warning("ABTA::NullLen", "BT recieved 0 len package");
                                currentOffset = 0;
                            }
                        }
                        currentOffset += bytes;
                    }
                    else
                    {
                        currentOffset += bytes;
                    }


                    while (currentLen > 0 && currentLen + 2 <= currentOffset)
                    {
                        _adapter.ThreadMessage_DataRead(buffer, 2, currentLen);
                        for (int i = currentLen + 2; i < currentOffset; i++)
                        {
                            buffer[i - (currentLen + 2)] = buffer[i];
                        }
                        currentOffset -= (currentLen + 2);

                        if (currentOffset > 2)
                        {
                            currentLen = NetworkDataTools.GetUInt16(buffer[0], buffer[1]);
                        }
                        else
                        {
                            currentLen = 0;
                        }
                    }
                }
                catch (Java.IO.IOException e)
                {
                    SAMLog.Warning("ABTA::ThreadRecieve_ConnLost", e.Message);
                    _adapter.ThreadMessage_ConnectionLost();
                    break;
                }
            }
        }