private const int SPP_PACKET_DATA_SIZE = 62; // This is because the mtu in wp is 63. private async Task SendJob(JobDesc job) { byte[] p = job.Data; int byte_sent = 0; int byte_to_send = p.Length; while (byte_to_send - byte_sent > 0) { int byteLeft = byte_to_send - byte_sent; int subPacketSize = byteLeft; if (subPacketSize > SPP_PACKET_DATA_SIZE) subPacketSize = SPP_PACKET_DATA_SIZE; byte[] temp = new byte[subPacketSize + 1]; temp[0] = 0; if (byte_sent == 0) temp[0] |= 0x01; if (subPacketSize == byteLeft) temp[0] |= 0x02; Array.Copy(p, byte_sent, temp, 1, subPacketSize); dataWriter.WriteBytes(temp); await dataWriter.StoreAsync(); await dataWriter.FlushAsync(); byte_sent += subPacketSize; } }