thijse / Arduino-CmdMessenger

CmdMessenger Communication library for Arduino & .NET
Other
208 stars 87 forks source link

Serial exception on Sleep and Disconnect. #29

Open pandabear41 opened 7 years ago

pandabear41 commented 7 years ago

So I am using cmdMessenger on a USB serial connection using the watchdog. Every time I sleep my computer and pull my desktop off the docking station. Once when the laptop wakes up I will get the following error and the app crashes.

System.ObjectDisposedException was unhandled Message: An unhandled exception of type 'System.ObjectDisposedException' occurred in mscorlib.dll Additional information: Safe handle has been closed

looking at a similar problem I found this. https://stackoverflow.com/questions/3230311/problem-with-serialport/7471010#7471010

I will do some more research and see if I can find a solution.

EDIT: BTW using .NET 4.5.2 on x64 Windows 10. It crashes with debugging on and off.

EDIT 2: Also found this. https://stackoverflow.com/questions/8927410/objectdisposedexception-when-closing-serialport-in-net-2-0 http://zachsaw.blogspot.com/2010/07/net-serialport-woes.html

EDIT 3: Couldn't find a trace within the code but enabling traces for native windows code I get this. Stack trace for SampleWatchdog

mscorlib.dll!System.StubHelpers.StubHelpers.SafeHandleAddRef(System.Runtime.InteropServices.SafeHandle pHandle, ref bool success)
System.dll!System.IO.Ports.SerialStream.EventLoopRunner.WaitForCommEvent()
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()