What happens when a timer is enabled but there is no code in the timer_timer()? Will it just keep running?
Thanks!
Printable View
What happens when a timer is enabled but there is no code in the timer_timer()? Will it just keep running?
Thanks!
Yes, but you would never know it because there is nothing that would indicate it is actually running.
Does it take processor time? Does it keep a form open?
The answer to both of those is probably, but each depends on exactly how the compiler is designed.
Why does it matter? (surely if there is a timer with no code, there is no point having it at all)
If a timer is enabled and the interval is non-zero, then it is running. Taking up processor time? Sure, but very little and maybe only when the timer actually fires. Even though you don't have any code, the timer fires at its interval to the timer control. The timer control calls your timer event and runs the code, if any. FYI: VB timers are windowed controls, so they do take some system resources while they exist.
I found this in my code and it must have been copied somehow into the form. The interval was set to 64. I did not intend to have this timer be in the program. It is no longer there or used. My question comes from the fact that some pretty funny (actually not funny) things are going on with the form. I am wondering if the timer was firing, even without any code in it, could it cause anything to happen?
As I mentioned, the timer will fire but it can't execute anything if you don't have any code in its event. We are talking about a VB timer control correct? Not some custom control?
I don't know exactly how a VB timer works, but here is my guess based on what I do know about it.
1. At runtime VB creates a window, this becomes the runtime timer
2. VB then applies an API timer to that window via SetTimer
3. The window receives WM_TIMER messages at the interval intended
The above is what I know; the following is a guess
4. VB implements an interface in your application that the timer window knows about
5. When the timer window gets a WM_Timer message, it calls that interface
6. That interface is your Timer_Timer event.
This goes on forever until you disable the timer, set its interval to zero, or the application closes -- which closes the timer window which destroys the API timer.
This is a vb timer control.
If the form performs an unload me does this end the timer?
The application stays open but the user close the form.
It sounds like if the timer is enabled that at least some action is being performed(Windows API), Am I correct to think that?
mojo69, I think you may be focusing on the wrong thing. A timer isn't going to prevent your forms from unloading or the app from closing, except in some rare cases, but especially not, if there is no code in the timer event.
I suspect you already tried removing the timer from your project? If not, do so, and see if your problems continue. If they do continue, look at the FAQs section regarding closing your application