mirror of
https://github.com/DarthAffe/OBD.NET.git
synced 2025-12-12 16:58:30 +00:00
Merge
This commit is contained in:
commit
43dd6968d9
@ -204,20 +204,24 @@ namespace OBD.NET.Common.Devices
|
|||||||
if (_queueSize == 0)
|
if (_queueSize == 0)
|
||||||
_queueEmptyEvent.Set();
|
_queueEmptyEvent.Set();
|
||||||
|
|
||||||
if (_commandQueue.TryTake(out CurrentCommand, 10, _commandCancellationToken.Token))
|
try
|
||||||
{
|
{
|
||||||
_queueSize--;
|
if (_commandQueue.TryTake(out CurrentCommand, 10, _commandCancellationToken.Token))
|
||||||
|
{
|
||||||
|
_queueSize--;
|
||||||
|
|
||||||
Logger?.WriteLine("Writing Command: '" + CurrentCommand.CommandText.Replace('\r', '\'') + "'", OBDLogLevel.Verbose);
|
Logger?.WriteLine("Writing Command: '" + CurrentCommand.CommandText.Replace('\r', '\'') + "'", OBDLogLevel.Verbose);
|
||||||
|
|
||||||
if (Connection.IsAsync)
|
if (Connection.IsAsync)
|
||||||
await Connection.WriteAsync(Encoding.ASCII.GetBytes(CurrentCommand.CommandText));
|
await Connection.WriteAsync(Encoding.ASCII.GetBytes(CurrentCommand.CommandText));
|
||||||
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
|
||||||
_commandFinishedEvent.WaitOne();
|
_commandFinishedEvent.WaitOne();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch (OperationCanceledException) { /*ignore, because it is thrown when the cancellation token is canceled*/}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user