mirror of
https://github.com/DarthAffe/OBD.NET.git
synced 2025-12-12 16:58:30 +00:00
Compare commits
4 Commits
d214f87fff
...
35af0f8c15
| Author | SHA1 | Date | |
|---|---|---|---|
| 35af0f8c15 | |||
| 1419ed7755 | |||
| b007471ed6 | |||
|
|
34940632a3 |
@ -197,6 +197,8 @@ 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;
|
||||||
@ -206,7 +208,7 @@ namespace OBD.NET.Common.Devices
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_commandQueue.TryTake(out CurrentCommand, 10, _commandCancellationToken.Token))
|
if (_commandQueue.TryTake(out CurrentCommand, 10, cancellationToken))
|
||||||
{
|
{
|
||||||
_queueSize--;
|
_queueSize--;
|
||||||
|
|
||||||
@ -217,12 +219,19 @@ 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
|
// wait for command to finish or command canceled
|
||||||
_commandFinishedEvent.WaitOne();
|
while (!_commandFinishedEvent.WaitOne(50))
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException) { /*ignore, because it is thrown when the cancellation token is canceled*/}
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
CurrentCommand?.CommandResult.WaitHandle.Set();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (QueuedCommand cmd in _commandQueue)
|
||||||
|
cmd.CommandResult.WaitHandle.Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WaitQueue() => _queueEmptyEvent.WaitOne();
|
public void WaitQueue() => _queueEmptyEvent.WaitOne();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user