1
0
mirror of https://github.com/DarthAffe/OBD.NET.git synced 2025-12-12 16:58:30 +00:00

Merge pull request #24 from MB512/fix/deadlock

Fix deadlock on connection lost
This commit is contained in:
DarthAffe 2021-11-03 23:35:10 +01:00 committed by GitHub
commit 1419ed7755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -217,11 +217,23 @@ 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) || _commandCancellationToken.IsCancellationRequested))
{
}
} }
} }
catch (OperationCanceledException) { /*ignore, because it is thrown when the cancellation token is canceled*/} catch (OperationCanceledException) { /*ignore, because it is thrown when the cancellation token is canceled*/}
// if canceled set all commands as completed (with null result)
if (_commandCancellationToken.IsCancellationRequested)
{
CurrentCommand?.CommandResult.WaitHandle.Set();
foreach (var cmd in _commandQueue)
{
cmd.CommandResult.WaitHandle.Set();
}
}
} }
} }