Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found a solution here: <a href="https://stackoverflow.com/questions/16110561/winrt-datareader-loadasync-exception-with-streamsocket-tcp">WinRT: DataReader.LoadAsync Exception with StreamSocket TCP</a></p> <p>I did only a few modifications:</p> <pre><code>public void Terminate() { try { if (socket != null) { taskLoadLength.Cancel(); taskLoadLength.Close(); taskLoadMessage.Cancel(); taskLoadMessage.Close(); socket.Dispose(); dataReadWorker.CancelAsync(); dataReader.Dispose(); dataWriter.Dispose(); isInicialized = false; } } catch (Exception e) { MessageBox.Show(e.Message); } } private void ReceiveMessages(object sender, DoWorkEventArgs ev) { while (true) { try { // Read first byte (length of the subsequent message, 255 or less). //uint sizeFieldCount = await dataReader.LoadAsync(1); taskLoadLength = dataReader.LoadAsync(1); taskLoadLength.AsTask().Wait(); uint sizeFieldCount = taskLoadLength.GetResults(); if (sizeFieldCount != 1) { // The underlying socket was closed before we were able to read the whole data. return; } // Read the message. uint messageLength = dataReader.ReadByte(); taskLoadMessage = dataReader.LoadAsync(messageLength); taskLoadMessage.AsTask().Wait(); uint actualMessageLength = taskLoadMessage.GetResults(); //uint actualMessageLength = await dataReader.LoadAsync(messageLength); if (messageLength != actualMessageLength) { // The underlying socket was closed before we were able to read the whole data. return; } // Read the message and process it. string message = dataReader.ReadString(actualMessageLength); MessageReceived(message); } catch (AggregateException ae) { MessageBox.Show(ae.Message); } catch (Exception e) { MessageBox.Show(e.Message); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload