1
0
mirror of https://github.com/DarthAffe/OBD.NET.git synced 2025-12-13 09:18:31 +00:00

Compare commits

..

No commits in common. "35af0f8c151cb33e635fc260e1fcaf21791e3991" and "d214f87fffdb19c05ce09295a9804d161a24becb" have entirely different histories.

View File

@ -197,8 +197,6 @@ namespace OBD.NET.Common.Devices
/// </summary> /// </summary>
private async void CommandWorker() private async void CommandWorker()
{ {
CancellationToken cancellationToken = _commandCancellationToken.Token;
while (!_commandCancellationToken.IsCancellationRequested) while (!_commandCancellationToken.IsCancellationRequested)
{ {
CurrentCommand = null; CurrentCommand = null;
@ -208,7 +206,7 @@ namespace OBD.NET.Common.Devices
try try
{ {
if (_commandQueue.TryTake(out CurrentCommand, 10, cancellationToken)) if (_commandQueue.TryTake(out CurrentCommand, 10, _commandCancellationToken.Token))
{ {
_queueSize--; _queueSize--;
@ -219,21 +217,14 @@ namespace OBD.NET.Common.Devices
else else
Connection.Write(Encoding.ASCII.GetBytes(CurrentCommand.CommandText)); Connection.Write(Encoding.ASCII.GetBytes(CurrentCommand.CommandText));
// wait for command to finish or command canceled //wait for command to finish
while (!_commandFinishedEvent.WaitOne(50)) _commandFinishedEvent.WaitOne();
cancellationToken.ThrowIfCancellationRequested();
} }
} }
catch (OperationCanceledException) catch (OperationCanceledException) { /*ignore, because it is thrown when the cancellation token is canceled*/}
{
CurrentCommand?.CommandResult.WaitHandle.Set();
} }
} }
foreach (QueuedCommand cmd in _commandQueue)
cmd.CommandResult.WaitHandle.Set();
}
public void WaitQueue() => _queueEmptyEvent.WaitOne(); public void WaitQueue() => _queueEmptyEvent.WaitOne();
public async Task WaitQueueAsync() => await Task.Run(() => WaitQueue()); public async Task WaitQueueAsync() => await Task.Run(() => WaitQueue());