|
-
May 29th, 2007, 02:26 AM
#1
Thread Starter
Addicted Member
2 Timers and a Single Sub
Hi. Hope you guys could help me. I just need to have to confirm what happens when I have this program code. I have two timers, both running concurrently. I have a single procedure which is called on both timers. Will it not have a conflict on local variables?
Code:
Public Sub tmrTimer1_Timer
ProcedureOne 1
End Sub
Public Sub tmrTimer2_Timer
ProcedureOne 2
End Sub
Private Sub ProcedureOne(ByVal x as integer)
'Statements
End Sub
I just need to confirm if calling the function from the second timer won't affect anything on the call from the first timer. Thank you very much
C++ Programming is overwhelming.
Dont let it overwhelm you or you'll fall into the oblivion of its perfection
-
May 29th, 2007, 02:51 AM
#2
Re: 2 Timers and a Single Sub
Why do you need two timers? I have NEVER needed more than 1.
-
May 29th, 2007, 03:53 AM
#3
Thread Starter
Addicted Member
Re: 2 Timers and a Single Sub
Because I need to check on two conditions simultaneously that is why I need to timers.
C++ Programming is overwhelming.
Dont let it overwhelm you or you'll fall into the oblivion of its perfection
-
May 29th, 2007, 04:10 AM
#4
Re: 2 Timers and a Single Sub
what are you doing with the variables in the procedure...
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
May 29th, 2007, 04:20 AM
#5
Thread Starter
Addicted Member
Re: 2 Timers and a Single Sub
The procedure retrieves records from the database and stores it on local variables.
My question is that if I called the same procedure twice on my program using timers (thus, it will be possible that two calls be simultaneous), will there be separate calls which will not affect the other call?
Am I clear on this one? I feel that you don't understand me. Thank you very much for the help
C++ Programming is overwhelming.
Dont let it overwhelm you or you'll fall into the oblivion of its perfection
-
May 29th, 2007, 04:23 AM
#6
Re: 2 Timers and a Single Sub
thanks for the explanation...I hope that the database will not allow two simultaneous calls to query it...so, dont worry about the simulatneous calls
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
May 29th, 2007, 07:34 AM
#7
Re: 2 Timers and a Single Sub
Timer control does not interrupt the code, it runs the code when the application is "free" (when application stopped executing and is waiting for the usre to do something, or when you have a DoEvents in the code)
The only time when ProcedureOne will be called while is already running is when you have DoEvents in your ProcedureOne sub (or in any subs/functions you call from the ProcedureOne sub).
[Edit]
By the way... Don't listen to people telling you not to use more than one timer... those people have bad preconceptions about the timer control, and there is nothing you can tell them to change their minds. I made an application that had ~50 timers (one or two in each form, but not all running at the same time, only 1 to 5 running at the same time) and the application was running just fine, and resources were fine also...
Last edited by CVMichael; May 29th, 2007 at 07:39 AM.
-
May 29th, 2007, 08:30 AM
#8
Re: 2 Timers and a Single Sub
 Originally Posted by randem
Why do you need two timers? I have NEVER needed more than 1.
I can think of a simple instance where two different timers is preferable to one: dragging nodes in a treeveiw.
One timer handles the "auto-expand" feature, which expands a node (if it has children) when the user hovers over it while dragging.
The second timer handles scrolling the treeview when the user drags past the top or bottom of the treeview.
I suppose it would be possible to re-use the same timer to handle both, but it would add a fair amount of needless complexity. Having said that, I do subscribe to the "re-use timers where feasible" mentality, so in the apps where I use treeviews, I have three. (The two drag timers, plus a third timer that everything else in the app shares.)
Last edited by Ellis Dee; May 29th, 2007 at 08:34 AM.
-
May 29th, 2007, 12:46 PM
#9
Re: 2 Timers and a Single Sub
Well, One timer calling 50 different routines would be more MAINTAINABLE than someone attempting to locate the code that is supposed to be run search through 50 timers since only one timer can run at any given time...
To prove this look at Timer Testing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|