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.
35af0f8c15
...
d214f87fff
@ -197,8 +197,6 @@ namespace OBD.NET.Common.Devices
|
||||
/// </summary>
|
||||
private async void CommandWorker()
|
||||
{
|
||||
CancellationToken cancellationToken = _commandCancellationToken.Token;
|
||||
|
||||
while (!_commandCancellationToken.IsCancellationRequested)
|
||||
{
|
||||
CurrentCommand = null;
|
||||
@ -208,7 +206,7 @@ namespace OBD.NET.Common.Devices
|
||||
|
||||
try
|
||||
{
|
||||
if (_commandQueue.TryTake(out CurrentCommand, 10, cancellationToken))
|
||||
if (_commandQueue.TryTake(out CurrentCommand, 10, _commandCancellationToken.Token))
|
||||
{
|
||||
_queueSize--;
|
||||
|
||||
@ -219,19 +217,12 @@ namespace OBD.NET.Common.Devices
|
||||
else
|
||||
Connection.Write(Encoding.ASCII.GetBytes(CurrentCommand.CommandText));
|
||||
|
||||
// wait for command to finish or command canceled
|
||||
while (!_commandFinishedEvent.WaitOne(50))
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
//wait for command to finish
|
||||
_commandFinishedEvent.WaitOne();
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
CurrentCommand?.CommandResult.WaitHandle.Set();
|
||||
}
|
||||
catch (OperationCanceledException) { /*ignore, because it is thrown when the cancellation token is canceled*/}
|
||||
}
|
||||
|
||||
foreach (QueuedCommand cmd in _commandQueue)
|
||||
cmd.CommandResult.WaitHandle.Set();
|
||||
}
|
||||
|
||||
public void WaitQueue() => _queueEmptyEvent.WaitOne();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user