serialport-lib-dotnet icon indicating copy to clipboard operation
serialport-lib-dotnet copied to clipboard

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

Open gitjsdr26 opened this issue 5 years ago • 5 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

gitjsdr26 avatar Apr 02 '20 15:04 gitjsdr26

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

genemars avatar Apr 03 '20 09:04 genemars

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

gitjsdr26 avatar Apr 03 '20 09:04 gitjsdr26

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

genemars avatar Apr 03 '20 09:04 genemars

but better do this in a different pull-request

genemars avatar Apr 03 '20 09:04 genemars

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

gitjsdr26 avatar Apr 03 '20 10:04 gitjsdr26

Fixed by #26

genemars avatar Oct 04 '23 06:10 genemars