StreamSocket _connection = AsyncCreateConnection(); // In constructor
private async void receive(){
DataReader reader = new DataReader(_connection.InputStream);
DataWriter writer = new DataWriter(_connection.OutputStream);
try
{
reader.InputStreamOptions = InputStreamOptions.Partial;
uint sizeFieldCount = await reader.LoadAsync(sizeof(uint)); // <<-- Explosion
if (sizeFieldCount != sizeof(uint))
{
return;
}
// Read the string.
uint stringLength = reader.ReadUInt32();
uint actualStringLength = await reader.LoadAsync(stringLength);
if (stringLength != actualStringLength)
{
return;
}
Debug.WriteLine(reader.ReadString(actualStringLength));
}
catch (Exception exc)
{
Debug.WriteLine(exc.Message);
}
}
整个下午都收到这个错误。创建连接的异步应该在调用接收方法时完成。