Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gitjsdr26 opened this issue Apr 2, 2020 · 6 comments

Comments

@gitjsdr26
Copy link

gitjsdr26 commented Apr 2, 2020

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

@genemars
Copy link
Member

genemars commented Apr 3, 2020

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

@gitjsdr26
Copy link
Author

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

@genemars
Copy link
Member

genemars commented Apr 3, 2020

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

@genemars
Copy link
Member

genemars commented Apr 3, 2020

but better do this in a different pull-request

@gitjsdr26
Copy link
Author

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

@genemars
Copy link
Member

genemars commented Oct 4, 2023

Fixed by #26

@genemars genemars closed this as completed Oct 4, 2023
genemars added a commit that referenced this issue Oct 4, 2023
- Fixes deadlock #20 #26
- Added `ReconnectDelay` property to get/set the reconnection delay in milliseconds - default = *1000* (closes #24)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants