Closed mclifford1 closed 2 weeks ago
See comment here: https://github.com/dotMorten/NmeaParser/issues/113#issuecomment-2487465292 CancellationToken appears to be broken for SerialPort's ReadAsync method.
Use this device instead: https://dotmorten.github.io/NmeaParser/api/netwin/NmeaParser.WinRTSerialDevice.html
Hello again,
I have noticed an issue (similar to #88) when calling CloseAsync() on an NmeaDevice (in my case a SerialPortDevice) in that it never returns. In my case the serial port is idle when this error is observed.
Looking at the source code I believe it is caused by:
in that the stream does not correctly react to the cancellation token internally (that is, inside the Stream.ReadAsync() itself) and terminate as it should.
This only hangs on an inactive serial port because an active port would be periodically checking the cancellation token and exit the read loop appropriately.
I found this thread discussing the issue and possible work-arounds. https://stackoverflow.com/questions/12421989/networkstream-readasync-with-a-cancellation-token-never-cancels
Best regards, Mark