1
0
mirror of https://github.com/DarthAffe/OBD.NET.git synced 2025-12-13 01:08:30 +00:00
This commit is contained in:
Darth Affe 2017-08-26 17:47:59 +02:00
commit 43dd6968d9

View File

@ -204,6 +204,8 @@ namespace OBD.NET.Common.Devices
if (_queueSize == 0) if (_queueSize == 0)
_queueEmptyEvent.Set(); _queueEmptyEvent.Set();
try
{
if (_commandQueue.TryTake(out CurrentCommand, 10, _commandCancellationToken.Token)) if (_commandQueue.TryTake(out CurrentCommand, 10, _commandCancellationToken.Token))
{ {
_queueSize--; _queueSize--;
@ -219,6 +221,8 @@ namespace OBD.NET.Common.Devices
_commandFinishedEvent.WaitOne(); _commandFinishedEvent.WaitOne();
} }
} }
catch (OperationCanceledException) { /*ignore, because it is thrown when the cancellation token is canceled*/}
}
} }
public void WaitQueue() => _queueEmptyEvent.WaitOne(); public void WaitQueue() => _queueEmptyEvent.WaitOne();
@ -230,9 +234,9 @@ namespace OBD.NET.Common.Devices
/// </summary> /// </summary>
public virtual void Dispose() public virtual void Dispose()
{ {
_commandQueue.CompleteAdding();
_commandCancellationToken?.Cancel(); _commandCancellationToken?.Cancel();
_commandWorkerTask?.Wait(); _commandWorkerTask?.Wait();
Connection?.Dispose(); Connection?.Dispose();
} }