I am writing a program (.net 4) that interacts with an external COM object. In the interest of having a “live” program, I am changing the program from polling the COM object and then doing calculations to receiving events from the COM object.
My issue is the events are too fast. As far as I can tell (in debug mode) some events are missed and so on.
The specific questions are:
- How do I (or C#) make sure I catch and handle all the events?
- How should the main be built to wait for an event (if there is a long time in between events) and not end?
I have tried a main with an infinite loop that sleeps for a millisecond and then spins off a thread, but that is just a big mess.
Thanks for your time
BackgroundWorkers is great for problems like this: –
You should continously poll for events by using a
Timer. You should simply handle the data as its received.Without more information this question will be difficult to answer in more detail….