04-18-2011 10:48 AM
Hi all,
I am using two timer controls in my application. One having the interval set to 50 ms and other having
interval set to 60 ms. When i try to run both timers the callback function of only 50 ms
timer runs perfectly. The callback of other timer doesn't run. Even if i set interval to 10 ms then
the callback function of that timer partially executes not complete. It only executes on the
occuring of any event for e.g holding the mouse key on a command button.
I want to execute both the timer callbacks simultaneously. My application is a single threaded application
and i am using processsystemevents( ) in the end of my code.
Any help will be greatly appreciated.
04-18-2011 11:16 AM
Do you know how much time every callback lasts? you may have problems if the elapsed time of one of the timer callbacks is too long, since the callback could be fired immediately after it has finished not leaving room for the other. Try running one timer only at a time tracing the elapsed time with something like that:
int timercallback (.......) { double tini = Timer (); if (event != EVENT_TIMER_TICK) return 0; // your code here DebugPrintf ("Elapsed time: %.0f msec\n", (Timer () - tini) * 1000.0); return 0; }
If the timer callback is too long you need to simply it at the maximum level in order to reduce it. Maybe you can transfer some task to the main thread with PostDeferredCall or try using an asynchronous timer for at least one of your timers (be warned that in this case you are moving to a multithreaded environment so you need to take the appropriate precautions to avoid concurrent access to shared resources / variables).
The following step could be to move to a full multithreaded application.
04-18-2011 01:56 PM
Forgot to say that 2 20Hz tasks on a Windows machine aren't a simple task to develop. Depending on the characteristics of the tasks (external instrument control, serial communications, file I/O, huge data handling) you may need to tailor the system itself in order to save resources to dedicate to your application: reduce active services, reduce programs activated at starup, disable antivirus...
It all depends on what is the program doing during its life.