mirror of
https://github.com/DarthAffe/OBD.NET.git
synced 2025-12-12 16:58:30 +00:00
This commit is contained in:
parent
d2c2b8456f
commit
6728f6413d
@ -222,22 +222,27 @@ namespace OBD.NET.Devices
|
|||||||
while (!commandCancellationToken.IsCancellationRequested)
|
while (!commandCancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
currentCommand = null;
|
currentCommand = null;
|
||||||
if(commandQueue.TryTake(out currentCommand, Timeout.Infinite, commandCancellationToken.Token))
|
try
|
||||||
{
|
{
|
||||||
Logger?.WriteLine("Writing Command: '" + currentCommand.CommandText.Replace('\r', '\'') + "'", OBDLogLevel.Verbose);
|
if (commandQueue.TryTake(out currentCommand, Timeout.Infinite, commandCancellationToken.Token))
|
||||||
|
|
||||||
if (Connection.IsAsync)
|
|
||||||
{
|
{
|
||||||
await Connection.WriteAsync(Encoding.ASCII.GetBytes(currentCommand.CommandText));
|
Logger?.WriteLine("Writing Command: '" + currentCommand.CommandText.Replace('\r', '\'') + "'", OBDLogLevel.Verbose);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Connection.Write(Encoding.ASCII.GetBytes(currentCommand.CommandText));
|
|
||||||
|
|
||||||
|
if (Connection.IsAsync)
|
||||||
|
{
|
||||||
|
await Connection.WriteAsync(Encoding.ASCII.GetBytes(currentCommand.CommandText));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Connection.Write(Encoding.ASCII.GetBytes(currentCommand.CommandText));
|
||||||
|
|
||||||
|
}
|
||||||
|
//wait for command to finish
|
||||||
|
commandFinishedEvent.WaitOne();
|
||||||
}
|
}
|
||||||
//wait for command to finish
|
|
||||||
commandFinishedEvent.WaitOne();
|
|
||||||
}
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{/*ignore, because it is thrown when the cancellation token is canceled*/}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,6 +251,7 @@ namespace OBD.NET.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