Need design for calling a method at regular intervals

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



In our app, we need to collect data at regular intervals (4, 8 or 16
seconds - user settable). The collection happens in a background
thread. My first approach was to do the collection, which takes about
0.5 seconds, then calculate how much time to sleep until the next
collection.

The problem is that when I cancel the collection, I have to wait for it
to emerge from the sleep before it actually exits. I could call
thread.Abort, but that seems frowned up.

A second approach is to have the collection loop wait for an event.
The event could be signalled from a Threading.Timer object or from the
user request.

Can I have your opinion on either of these approaches, or any othe
suggestions?

Thanks

Mitch

.



Relevant Pages

  • Re: Sleep API function
    ... > using Sleep ....". ... IIRC the warnings are mainly because it makes the app that is calling it ... >> to explorer while the VB app runs in the background. ... it was a background app that I didn't care would show as 'not responding' ...
    (microsoft.public.vb.winapi)
  • Re: iPhone being exposed on Watchdog!
    ... then the app gets terminated. ... Do people really leave applications running when they sleep their ... so full of outrage. ... We need to be angry, but now we're less likely to ...
    (uk.comp.sys.mac)
  • Re: processor time allocation
    ... When an app is doing IO it does NOT show up in the task manager as process ... simply stating that my process is not getting cpu time really doesn't give ... > perfectly fine using Sleep to obtain a near 20 Hz frequency. ... > Which is that my App is CPU starved and windows wont give my app more than ...
    (microsoft.public.vc.mfc)
  • Re: Notification of WIndows Shutdown.
    ... other application is done (checks a registry entry) then it does its ... If you are coming out of a Sleep API call and then immediately ... I think Bob is spot on here. ... Your app does not shut down because the form gets ...
    (microsoft.public.vb.general.discussion)
  • Re: Timing your loops
    ... Instead of taking a 'greedy' approach that uses up as much CPU time as possible unless you remember to stop it, have you considered an approach whereby you generally do nothing, but occasionally you'll render a frame? ... Providing your timer-handling code takes less than 30ms to execute, your app should go back to sleep between frames. ... After all they are running and while doing nothing are allocated all the cpu power left....mustn't be left for a rainy day after all. ...
    (microsoft.public.win32.programmer.directx.managed)