genielabs/serialport-lib-dotnet

Closing Port COM while receiving data often creates a Deadlock in application

gitjsdr26 opened this issue · 6 comments

Hi,

I found an issue when closing Port COM while sending data. It creates a Deadlock in the application.
This is the stack trace below :

[En attente du verrou détenu par le thread 4156]	
WindowsBase.dll!System.Windows.Threading.DispatcherSynchronizationContext.Wait(System.IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)	
[Transition Natif à Managé]	
[Transition Managé à Natif]	
System.dll!System.IO.Ports.SerialStream.Dispose(bool disposing)
mscorlib.dll!System.IO.Stream.Close()
System.dll!System.IO.Ports.SerialPort.Dispose(bool disposing)
System.dll!System.IO.Ports.SerialPort.Close()

The execution pointer is blocked in method

private void Close()

when executing

_serialPort.Close();

I think that this deadlock occurs in native Framework SerialPort.
I've no idea how to solve this, beside waiting the end of transmission...

See this thread : https://social.msdn.microsoft.com/Forums/en-US/ce8ce1a3-64ed-4f26-b9ad-e2ff1d3be0a5/serial-port-hangs-whilst-closing?forum=Vsexpressvcs

Regards

yes this might be a problem in the core libraries, so we can ignore it.

But can we try to find a working workaround and then put it into the library ?

Yes if the work-around can be done in serial-port-lib.

but better do this in a different pull-request

Actually I didn't found a stable workaround. If I do, I'll post a pull request.
Regards.