Timer
-
Can anyone shed any light on the reason why when I execute the following code to set a time for 1 minute, i.e. 60000 milliseconds it takes around 3 minutes for the timer to 'tick'.
public void setCheckInterval(int i_checkInterval) { switch (i_checkInterval) { case 0: _i_checkInterval = -1; break; case 1: _i_checkInterval = 60000; break; case 2: _i_checkInterval = 60000 * 3; break; case 3: _i_checkInterval = 60000 * 5; break; case 4: _i_checkInterval = 60000 * 10; break; case 5: _i_checkInterval = 60000 * 15; break; case 6: _i_checkInterval = 60000 * 20; break; case 7: _i_checkInterval = 60000 * 25; break; case 8: _i_checkInterval = 60000 * 30; break; case 9: _i_checkInterval = 60000 * 60; break; } ...
Freedom is the right to say that 2+2=5 if this is so everything else will follow.
-
Can anyone shed any light on the reason why when I execute the following code to set a time for 1 minute, i.e. 60000 milliseconds it takes around 3 minutes for the timer to 'tick'.
public void setCheckInterval(int i_checkInterval) { switch (i_checkInterval) { case 0: _i_checkInterval = -1; break; case 1: _i_checkInterval = 60000; break; case 2: _i_checkInterval = 60000 * 3; break; case 3: _i_checkInterval = 60000 * 5; break; case 4: _i_checkInterval = 60000 * 10; break; case 5: _i_checkInterval = 60000 * 15; break; case 6: _i_checkInterval = 60000 * 20; break; case 7: _i_checkInterval = 60000 * 25; break; case 8: _i_checkInterval = 60000 * 30; break; case 9: _i_checkInterval = 60000 * 60; break; } ...
Freedom is the right to say that 2+2=5 if this is so everything else will follow.
I am not really sure how we are supose to figure out your problem from the code you have posted. Usually if you want a more accurate timer you should use the System.Timer not the standard one you get in your tool box. To get the System.timer, right click on yrou tool box, select choose item. In the .net tab look for the system.timer and select it. Now you should have the system.timer in your tool box. Note without seeing your other code it is hard to say why the event isn't firing on time. I would guess it has to do with some other threads are keeping the CPU busy. I would guess there is something else in your code that isn't probably working they way you expect it to. If you just let the timer run by it self without anything else running and check your watch, I would guess you would see that the event would fire pretty close to 60 later. Ben
-
Can anyone shed any light on the reason why when I execute the following code to set a time for 1 minute, i.e. 60000 milliseconds it takes around 3 minutes for the timer to 'tick'.
public void setCheckInterval(int i_checkInterval) { switch (i_checkInterval) { case 0: _i_checkInterval = -1; break; case 1: _i_checkInterval = 60000; break; case 2: _i_checkInterval = 60000 * 3; break; case 3: _i_checkInterval = 60000 * 5; break; case 4: _i_checkInterval = 60000 * 10; break; case 5: _i_checkInterval = 60000 * 15; break; case 6: _i_checkInterval = 60000 * 20; break; case 7: _i_checkInterval = 60000 * 25; break; case 8: _i_checkInterval = 60000 * 30; break; case 9: _i_checkInterval = 60000 * 60; break; } ...
Freedom is the right to say that 2+2=5 if this is so everything else will follow.
Hello,
MicealG wrote:
public void setCheckInterval(int i_checkInterval) { switch (i_checkInterval) { case 0: _i_checkInterval = -1; break; case 1: _i_checkInterval = 60000; break; case 2: _i_checkInterval = 60000 * 3; break; case 3: _i_checkInterval = 60000 * 5; break; case 4: _i_checkInterval = 60000 * 10; break; case 5: _i_checkInterval = 60000 * 15; break; case 6: _i_checkInterval = 60000 * 20; break; case 7: _i_checkInterval = 60000 * 25; break; case 8: _i_checkInterval = 60000 * 30; break; case 9: _i_checkInterval = 60000 * 60; break; } ...
What should this method tell us?
MicealG wrote:
Can anyone shed any light on the reason why when I execute the following code to set a time for 1 minute, i.e. 60000 milliseconds it takes around 3 minutes for the timer to 'tick'.
One reason could be that you use the System.Windows.Forms.Timer (Off course you do because you said 'Tick'), which runs in the UI thread. This can be blocked from the busy UI. If you need it more time secure you could use System.Timers.Timer or System.Threading.Timer. Hope it helps, All the best, Martin
-
Can anyone shed any light on the reason why when I execute the following code to set a time for 1 minute, i.e. 60000 milliseconds it takes around 3 minutes for the timer to 'tick'.
public void setCheckInterval(int i_checkInterval) { switch (i_checkInterval) { case 0: _i_checkInterval = -1; break; case 1: _i_checkInterval = 60000; break; case 2: _i_checkInterval = 60000 * 3; break; case 3: _i_checkInterval = 60000 * 5; break; case 4: _i_checkInterval = 60000 * 10; break; case 5: _i_checkInterval = 60000 * 15; break; case 6: _i_checkInterval = 60000 * 20; break; case 7: _i_checkInterval = 60000 * 25; break; case 8: _i_checkInterval = 60000 * 30; break; case 9: _i_checkInterval = 60000 * 60; break; } ...
Freedom is the right to say that 2+2=5 if this is so everything else will follow.
I second what the other two said, but I prefer to look for the easy solutions first. Like checking the value of
i_checkInteral
. Seems to me that it's value is actually 2, right where you set the timer for 3 minutes, when you expect it to be 1.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
I second what the other two said, but I prefer to look for the easy solutions first. Like checking the value of
i_checkInteral
. Seems to me that it's value is actually 2, right where you set the timer for 3 minutes, when you expect it to be 1.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Hello Dave, Please tell me, what the h... is this method doing? Is it a second timer which checks the first?:confused: Thanks for your time Martin
It's a method, called by some unknown, that just sets a misguidedly-used global variable. What happens after that, I have no idea.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Can anyone shed any light on the reason why when I execute the following code to set a time for 1 minute, i.e. 60000 milliseconds it takes around 3 minutes for the timer to 'tick'.
public void setCheckInterval(int i_checkInterval) { switch (i_checkInterval) { case 0: _i_checkInterval = -1; break; case 1: _i_checkInterval = 60000; break; case 2: _i_checkInterval = 60000 * 3; break; case 3: _i_checkInterval = 60000 * 5; break; case 4: _i_checkInterval = 60000 * 10; break; case 5: _i_checkInterval = 60000 * 15; break; case 6: _i_checkInterval = 60000 * 20; break; case 7: _i_checkInterval = 60000 * 25; break; case 8: _i_checkInterval = 60000 * 30; break; case 9: _i_checkInterval = 60000 * 60; break; } ...
Freedom is the right to say that 2+2=5 if this is so everything else will follow.
I am guessing you have a control (probably a combobox) that is used to select one out of a list of time periods. If so, use the selected combobox text rather than the selected index, and do some simple math, something like:
const int MILLISECONDS_PER_MINUTE=60*1000; // outside any method !
...
int delayInMsecs=MILLISECONDS_PER_MINUTE*Convert.ToInt32(myCombo.Text)This eliminates all the code you have shown and a lot of possible bugs, and it is immediately clear what is going on. :)
Luc Pattyn [My Articles] [Forum Guidelines]