The thread xyz has exited with code 259 (0x103)

Topics: Bluetooth - Windows Phone 8, Samples
Apr 1, 2014 at 3:14 AM
Hi,

I have problems with bluetooth connection. It is endless connection and after several seconds it is always hangs up on ReadAsync with information:

The thread 0x19c has exited with code 259 (0x103).
The program '[5612] TaskHost.exe' has exited with code 0 (0x0).

After this - connection is still valid with device (I see connection diode on device), but there is no chance to:
1) Connect again to device (connection is still present)
2) Receive any data from socket/connection

It is allways hanging here:
returnedBuffer =
                    await
                        socket.InputStream.ReadAsync(buffer.AsBuffer(), (uint)buffer.Length,
                            InputStreamOptions.Partial);
Code is from your sample:

private async void ReadThread(object host)
    {
        reading = true;

        var socket = new StreamSocket();
        socket.Control.KeepAlive = true;
        socket.Control.NoDelay = false;
        //socket.Control.QualityOfService = SocketQualityOfService.LowLatency;

        IAsyncAction a = StreamSocketExtensions.ConnectAsync(socket, (HostName)host, RfcommServiceId.SerialPort);
        await a;

        var buffer = new byte[2048];

        while (reading)
        {
            IBuffer returnedBuffer = null;
            try
            {
                returnedBuffer =
                    await
                        socket.InputStream.ReadAsync(buffer.AsBuffer(), (uint)buffer.Length,
                            InputStreamOptions.Partial);
                if (returnedBuffer != null)
                {

                    string s = PrintByteArray(returnedBuffer.ToArray(), (int)returnedBuffer.Length);

                    if (!string.IsNullOrEmpty(s))
                    {


                        Dispatcher.BeginInvoke(new Action<string>(InsertMessage), s);


                    }
                }
            }
            catch
            {

            }

        }

        socket.Dispose();
    }
Regards
Mateusz