Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SmRtAPI/SmRtAPI/MessageWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task Start()
var streamBuffer = new byte[_api.Configuration.BlockSize];
int bytesRead;

while ((bytesRead = await _stream.ReadAsync(streamBuffer, 0, streamBuffer.Length)) > 0 && !_transcriptionComplete.WaitOne(0))
while ((bytesRead = await _stream.ReadAsync(streamBuffer, 0, streamBuffer.Length, _api.CancelToken)) > 0 && !_transcriptionComplete.WaitOne(0))
{
await SendData(new ArraySegment<byte>(streamBuffer, 0, bytesRead));
_sequenceNumber++;
Expand Down
24 changes: 20 additions & 4 deletions SmRtAPI/SmRtAPI/SmRtApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,32 @@ public async Task RunAsync()
/* The reading loop */
var t1 = Task.Factory.StartNew(async () =>
{
var reader = new MessageReader(this, wsClient, transcriptionComplete, recognitionStarted);
await reader.Start();
try
{
var reader = new MessageReader(this, wsClient, transcriptionComplete, recognitionStarted);
await reader.Start();
}
catch (OperationCanceledException)
{
transcriptionComplete.Set();
}


}, CancelToken, TaskCreationOptions.LongRunning, TaskScheduler.Default);

/* The writing loop */
var t2 = Task.Factory.StartNew(async () =>
{
_writer = new MessageWriter(this, wsClient, transcriptionComplete, _stream, recognitionStarted);
await _writer.Start();
try
{
_writer = new MessageWriter(this, wsClient, transcriptionComplete, _stream, recognitionStarted);
await _writer.Start();
}
catch (OperationCanceledException)
{
transcriptionComplete.Set();
}

}, CancelToken, TaskCreationOptions.LongRunning, TaskScheduler.Default);

transcriptionComplete.WaitOne();
Expand Down