internal async void RepeatAsyncRead() { //_socket.InputStream.ReadAsync(_buf.AsBuffer(), (uint)_buf.Length, Windows.Storage.Streams.InputStreamOptions.Partial).Completed = RepeatCallback; await Task.Run(async() => { while (true) { try { IBuffer result = await _socket.InputStream.ReadAsync(_buf.AsBuffer(), (uint)_buf.Length, Windows.Storage.Streams.InputStreamOptions.Partial); if (result.Length > 0) { //await _handler.OnData(_buf, 0, (int)result.Length); _handler.OnData(_buf, 0, (int)result.Length); } else if (result.Length < 0) { //await _handler.OnData(_buf, 0, (int)result.Length*-1); _handler.OnData(_buf, 0, (int)result.Length * -1); } else { _handler.OnClosed(); return; } } catch (Exception ex) { if (!_closed) { _handler.OnError(ex, ex.Message); } else { _handler.OnClosed(); } return; } } }); }
public void OnData(byte[] data, int offset, int length) //public IAsyncAction OnData(byte[] data, int offset, int length) { //return Task.Run(async () => { await _handler.OnData(data, offset, length); }).AsAsyncAction(); _handler.OnData(data, offset, length); }