[STAThread] static void Main()
This is very unreasonable, you are breaking the STAThread contract. This means that you must pump the outline of the message. Application.Run () in a .NET program. You did it right for a thread that displays the user interface, but not for the main thread. The one you are supposed to use to talk with the device.
The worst problem is that it will look easy as if you can handle it. But this is a quiet time bomb that is ready to explode in your face at any time. Misbehavior varies from an arbitrary deadlock, especially from the unpleasant look that causes the .NET finalizer thread to hang. It happens when the CLR tries to free the shell of COM interop. It is very difficult to diagnose, your program eventually crashes when memory runs out. It takes some time, invariably longer than your patience checking the application. The random incorrect behavior of the counter object itself, usually diagnosed by a call to lock the object or the object that does not raise the expected event.
Finishing the finalizer deadlock is by far the worst problem, bad enough to make you change that. Focus on the real problem, this is the counter code that behaves incorrectly. Give him a safe harbor on his own, a properly designed STA jet that pumps. You will find the code for the boiler plate in this message . Or simply change the attribute to [MTAThread], which forces COM to provide a safe haven for the COM object on its own. But itβs better to take the bull with your horn so that you know what is happening, instead of relying on indestructible black magic.
I also highly recommend contacting the supplier or author of this component. Mesh COM servers should not behave this way. Something is wrong.
source share