• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to Generate an Accurate Timer Tick

C

Charles

#1
I asked a question related to this a little while ago, and thought that I'd
got my answer, but it has come back to bite me again.

I currently use a System.Threading.Timer to generate a tick every 10
seconds. At each tick, I execute some code that will take a maximum of 5
seconds to complete. Most of the time, each subsequent tick occurs at
exactly 10 seconds after the previous one, but occasionally there can be as
much as 20 or 30 seconds between ticks.

It was explained, in the previous thread, that the Threading timer relies on
WM_TIMER messages, which are low down on the priority list. If the system
gets a bit busy then these message seem to come further apart, so my tick
interval extends.

What I need is a reliable way to generate a 10 second tick, that still works
when the system gets a bit busy. I'm running this on Windows Server 2003 R2
x64, if that makes any difference.

Does anyone have any ideas?

TIA

Charles
 

My Computer

F

Family Tree Mike

#2
On 5/20/2010 9:51 AM, Charles wrote:

> I asked a question related to this a little while ago, and thought that
> I'd got my answer, but it has come back to bite me again.
>
> I currently use a System.Threading.Timer to generate a tick every 10
> seconds. At each tick, I execute some code that will take a maximum of 5
> seconds to complete. Most of the time, each subsequent tick occurs at
> exactly 10 seconds after the previous one, but occasionally there can be
> as much as 20 or 30 seconds between ticks.
>
> It was explained, in the previous thread, that the Threading timer
> relies on WM_TIMER messages, which are low down on the priority list. If
> the system gets a bit busy then these message seem to come further
> apart, so my tick interval extends.
>
> What I need is a reliable way to generate a 10 second tick, that still
> works when the system gets a bit busy. I'm running this on Windows
> Server 2003 R2 x64, if that makes any difference.
>
> Does anyone have any ideas?
>
> TIA
>
> Charles
>
>
To get exactly 10 seconds between ticks, you need a real-time operating
system. Windows is not a real-time OS. You will need to rethink the
requirement, or rethink the computing platform.

--
Mike
 

My Computer

D

DickGrier

#4
As Mike said, Windows is not a real-time OS. Thus, you cannot guarantee
response.

That said, you may be able to approach the accuracy that you desire. One
thing to realize is that resolution and accuracy are not the same thing.
And, since you will be writing code that is multi-threaded (and you have
only gross control of the various thread execution), and, in addition, are
executing in a non-deterministic OS, you have to careful what you ask for --
and understand that you can never be absolutely certain that you will get
the precision that you seek.

If you use a timer, you depend on multiple things, including the wm_timer
message. You might simply create a thread that monitors elapsed
milliseconds (example: Now.TimeOfDay.TotalMilliseconds). This will be more
accurate than the built-in timer. It will not, however, provide any real
determinism, so at the end of the day, you have to test it under load and
see if it meets your needs. If not... You may not be able to get there from
here.

Dick
--
Richard Grier, Consultant, Hard & Software 12962 West Louisiana Avenue
Lakewood, CO 80228 303-986-2179 (voice) Homepage: www.hardandsoftware.net
Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004, Revised July
2006.
 

My Computer

C

Charles

#5
Hi Mike

Thanks for the reply. To be honest, I'd be happy with 10 seconds +/- 5
seconds, which doesn't seem to much to ask. Or is it?

Charles


"Family Tree Mike" <FamilyTreeMike@newsgroup> wrote in message
news:#NQkzUD#KHA.5464@newsgroup

> On 5/20/2010 9:51 AM, Charles wrote:

>> I asked a question related to this a little while ago, and thought that
>> I'd got my answer, but it has come back to bite me again.
>>
>> I currently use a System.Threading.Timer to generate a tick every 10
>> seconds. At each tick, I execute some code that will take a maximum of 5
>> seconds to complete. Most of the time, each subsequent tick occurs at
>> exactly 10 seconds after the previous one, but occasionally there can be
>> as much as 20 or 30 seconds between ticks.
>>
>> It was explained, in the previous thread, that the Threading timer
>> relies on WM_TIMER messages, which are low down on the priority list. If
>> the system gets a bit busy then these message seem to come further
>> apart, so my tick interval extends.
>>
>> What I need is a reliable way to generate a 10 second tick, that still
>> works when the system gets a bit busy. I'm running this on Windows
>> Server 2003 R2 x64, if that makes any difference.
>>
>> Does anyone have any ideas?
>>
>> TIA
>>
>> Charles
>>
>>
>
> To get exactly 10 seconds between ticks, you need a real-time operating
> system. Windows is not a real-time OS. You will need to rethink the
> requirement, or rethink the computing platform.
>
> --
> Mike
 

My Computer

C

Charles

#6
Hi Dave

Yes, I have. It was my understanding that the Timers timer was just a
wrapper for the Threading timer. Perhaps not. There doesn't seem to be
anything there that suggests it is any more reliable the the threading
version. If it doesn't use WM_TIMER messages, do you know how it does work?

Thanks

Charles


"Davej" <galt_57@newsgroup> wrote in message
news:a38d2fce-5230-42bd-833c-e9b6748bf691@newsgroup

> On May 20, 8:51 am, "Charles" <bl...@newsgroup> wrote:

>> [...] Most of the time, each subsequent tick occurs at
>> exactly 10 seconds after the previous one, but occasionally
>> there can be as much as 20 or 30 seconds between ticks.
>>
>
> You've looked here?
>
> http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
>
 

My Computer

C

Charles

#7
Hi Dick

As I replied to Mike, 10 +/- 5 seconds would do me. I have to send a
keep-alive message to another system approximately every 10 seconds. The
other end will time-out after 25 seconds or so, which doesn't seem too tight
a window, and yet sometimes the interval between ticks can be 30 seconds or
mor. I wondered about monitoring elapsed seconds, but it just seemed a bit
kludgy. I can't imagine I'm the only person that does this sort of thing in
Windows. How do other applications do it, I wonder, where they have to
perform tasks at regular intervals, with a reasonable degree of accuracy?

Charles


"DickGrier" <dick_grierNOSPAM@newsgroup> wrote in message
news:u4PzjnD#KHA.1888@newsgroup

> As Mike said, Windows is not a real-time OS. Thus, you cannot guarantee
> response.
>
> That said, you may be able to approach the accuracy that you desire. One
> thing to realize is that resolution and accuracy are not the same thing.
> And, since you will be writing code that is multi-threaded (and you have
> only gross control of the various thread execution), and, in addition, are
> executing in a non-deterministic OS, you have to careful what you ask
> for -- and understand that you can never be absolutely certain that you
> will get the precision that you seek.
>
> If you use a timer, you depend on multiple things, including the wm_timer
> message. You might simply create a thread that monitors elapsed
> milliseconds (example: Now.TimeOfDay.TotalMilliseconds). This will be
> more accurate than the built-in timer. It will not, however, provide any
> real determinism, so at the end of the day, you have to test it under load
> and see if it meets your needs. If not... You may not be able to get
> there from here.
>
> Dick
> --
> Richard Grier, Consultant, Hard & Software 12962 West Louisiana Avenue
> Lakewood, CO 80228 303-986-2179 (voice) Homepage: www.hardandsoftware.net
> Author of Visual Basic Programmer's Guide to Serial Communications, 4th
> Edition ISBN 1-890422-28-2 (391 pages) published July 2004, Revised July
> 2006.
 

My Computer

C

Cor Ligthert[MVP]

#8
Then why not use the standard Windows.Forms.Form.Timer, somehow persons want
to use the system.timer.timer (the windows service one) or the threading
timer (who is able to be used in async)

I am glad that you are not writing of the current fourth one the dispatcher
timer.

People always write about all timers beside the windows.forms.form.timer
that the others are better, but never tell why those are better.

The windows.forms.form timer is at least the most reliable one in most
situations

Cor

"Charles" <blank@newsgroup> wrote in message
news:#S6R67E#KHA.1652@newsgroup

> Hi Dave
>
> Yes, I have. It was my understanding that the Timers timer was just a
> wrapper for the Threading timer. Perhaps not. There doesn't seem to be
> anything there that suggests it is any more reliable the the threading
> version. If it doesn't use WM_TIMER messages, do you know how it does
> work?
>
> Thanks
>
> Charles
>
>
> "Davej" <galt_57@newsgroup> wrote in message
> news:a38d2fce-5230-42bd-833c-e9b6748bf691@newsgroup

>> On May 20, 8:51 am, "Charles" <bl...@newsgroup> wrote:

>>> [...] Most of the time, each subsequent tick occurs at
>>> exactly 10 seconds after the previous one, but occasionally
>>> there can be as much as 20 or 30 seconds between ticks.
>>>
>>
>> You've looked here?
>>
>> http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
>>
 

My Computer

C

Charles

#9
Hi Cor, good to hear from you.

I have read that the Forms timer is actually less reliable in terms of its
interval than the other timers, because it is single-threaded. Coupled with
the fact that I want to use this in a service eventually, I don't think I
can use the Forms timer.

Cheers

Charles


"Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
news:#3x7yxK#KHA.4308@newsgroup

> Then why not use the standard Windows.Forms.Form.Timer, somehow persons
> want to use the system.timer.timer (the windows service one) or the
> threading timer (who is able to be used in async)
>
> I am glad that you are not writing of the current fourth one the
> dispatcher timer.
>
> People always write about all timers beside the windows.forms.form.timer
> that the others are better, but never tell why those are better.
>
> The windows.forms.form timer is at least the most reliable one in most
> situations
>
> Cor
>
> "Charles" <blank@newsgroup> wrote in message
> news:#S6R67E#KHA.1652@newsgroup

>> Hi Dave
>>
>> Yes, I have. It was my understanding that the Timers timer was just a
>> wrapper for the Threading timer. Perhaps not. There doesn't seem to be
>> anything there that suggests it is any more reliable the the threading
>> version. If it doesn't use WM_TIMER messages, do you know how it does
>> work?
>>
>> Thanks
>>
>> Charles
>>
>>
>> "Davej" <galt_57@newsgroup> wrote in message
>> news:a38d2fce-5230-42bd-833c-e9b6748bf691@newsgroup

>>> On May 20, 8:51 am, "Charles" <bl...@newsgroup> wrote:
>>>> [...] Most of the time, each subsequent tick occurs at
>>>> exactly 10 seconds after the previous one, but occasionally
>>>> there can be as much as 20 or 30 seconds between ticks.
>>>>
>>>
>>> You've looked here?
>>>
>>> http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
>>>
 

My Computer

C

Cor Ligthert[MVP]

#10
There is also written that American cars are better than German cars.

Do you believe everything which is written without anything which explains
why?

Take a look at this page which compares timers.

http://msdn.microsoft.com/en-us/magazine/cc164015.aspx

You can handle them top down like in this page as long as something where
they don't work fail.

Cor



"Charles" <blank@newsgroup> wrote in message
news:e7o3vHM#KHA.5916@newsgroup

> Hi Cor, good to hear from you.
>
> I have read that the Forms timer is actually less reliable in terms of its
> interval than the other timers, because it is single-threaded. Coupled
> with the fact that I want to use this in a service eventually, I don't
> think I can use the Forms timer.
>
> Cheers
>
> Charles
>
>
> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
> news:#3x7yxK#KHA.4308@newsgroup

>> Then why not use the standard Windows.Forms.Form.Timer, somehow persons
>> want to use the system.timer.timer (the windows service one) or the
>> threading timer (who is able to be used in async)
>>
>> I am glad that you are not writing of the current fourth one the
>> dispatcher timer.
>>
>> People always write about all timers beside the windows.forms.form.timer
>> that the others are better, but never tell why those are better.
>>
>> The windows.forms.form timer is at least the most reliable one in most
>> situations
>>
>> Cor
>>
>> "Charles" <blank@newsgroup> wrote in message
>> news:#S6R67E#KHA.1652@newsgroup

>>> Hi Dave
>>>
>>> Yes, I have. It was my understanding that the Timers timer was just a
>>> wrapper for the Threading timer. Perhaps not. There doesn't seem to be
>>> anything there that suggests it is any more reliable the the threading
>>> version. If it doesn't use WM_TIMER messages, do you know how it does
>>> work?
>>>
>>> Thanks
>>>
>>> Charles
>>>
>>>
>>> "Davej" <galt_57@newsgroup> wrote in message
>>> news:a38d2fce-5230-42bd-833c-e9b6748bf691@newsgroup
>>>> On May 20, 8:51 am, "Charles" <bl...@newsgroup> wrote:
>>>>> [...] Most of the time, each subsequent tick occurs at
>>>>> exactly 10 seconds after the previous one, but occasionally
>>>>> there can be as much as 20 or 30 seconds between ticks.
>>>>>
>>>>
>>>> You've looked here?
>>>>
>>>> http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
>>>>
 

My Computer

J

Jeff Gaines

#11
On 21/05/2010 in message <OoAId2M#KHA.4768@newsgroup> Cor
Ligthert[MVP] wrote:

>There is also written that American cars are better than German cars.
But only by Americans I would think!

--
Jeff Gaines Dorset UK
All things being equal, fat people use more soap
 

My Computer

C

Charles

#12
Have you actually read the article, Cor? I have. It bears out exactly what I
said: "System.Windows.Forms.Timer
If you're looking for a metronome, you've come to the wrong place."

Charles


"Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
news:OoAId2M#KHA.4768@newsgroup

> There is also written that American cars are better than German cars.
>
> Do you believe everything which is written without anything which explains
> why?
>
> Take a look at this page which compares timers.
>
> http://msdn.microsoft.com/en-us/magazine/cc164015.aspx
>
> You can handle them top down like in this page as long as something where
> they don't work fail.
>
> Cor
>
>
>
> "Charles" <blank@newsgroup> wrote in message
> news:e7o3vHM#KHA.5916@newsgroup

>> Hi Cor, good to hear from you.
>>
>> I have read that the Forms timer is actually less reliable in terms of
>> its interval than the other timers, because it is single-threaded.
>> Coupled with the fact that I want to use this in a service eventually, I
>> don't think I can use the Forms timer.
>>
>> Cheers
>>
>> Charles
>>
>>
>> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
>> news:#3x7yxK#KHA.4308@newsgroup

>>> Then why not use the standard Windows.Forms.Form.Timer, somehow persons
>>> want to use the system.timer.timer (the windows service one) or the
>>> threading timer (who is able to be used in async)
>>>
>>> I am glad that you are not writing of the current fourth one the
>>> dispatcher timer.
>>>
>>> People always write about all timers beside the windows.forms.form.timer
>>> that the others are better, but never tell why those are better.
>>>
>>> The windows.forms.form timer is at least the most reliable one in most
>>> situations
>>>
>>> Cor
>>>
>>> "Charles" <blank@newsgroup> wrote in message
>>> news:#S6R67E#KHA.1652@newsgroup
>>>> Hi Dave
>>>>
>>>> Yes, I have. It was my understanding that the Timers timer was just a
>>>> wrapper for the Threading timer. Perhaps not. There doesn't seem to be
>>>> anything there that suggests it is any more reliable the the threading
>>>> version. If it doesn't use WM_TIMER messages, do you know how it does
>>>> work?
>>>>
>>>> Thanks
>>>>
>>>> Charles
>>>>
>>>>
>>>> "Davej" <galt_57@newsgroup> wrote in message
>>>> news:a38d2fce-5230-42bd-833c-e9b6748bf691@newsgroup
>>>>> On May 20, 8:51 am, "Charles" <bl...@newsgroup> wrote:
>>>>>> [...] Most of the time, each subsequent tick occurs at
>>>>>> exactly 10 seconds after the previous one, but occasionally
>>>>>> there can be as much as 20 or 30 seconds between ticks.
>>>>>>
>>>>>
>>>>> You've looked here?
>>>>>
>>>>> http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
>>>>>
 

My Computer

C

Cor Ligthert[MVP]

#14
That was the first sentence, did you read all of it?

While I advices you already earlier to use in a windows service a windows
timer timer, because in that a windows forms timer does not go.

You where not asking about picoseconds precise timer, that has been
elaborated already more then enough in this thread.

But if you don't want to use the windows timer timer, feel free, it cost me
at least nothing.

Cor

"Charles" <blank@newsgroup> wrote in message
news:uRLGmlN#KHA.1652@newsgroup

> Have you actually read the article, Cor? I have. It bears out exactly what
> I said: "System.Windows.Forms.Timer
> If you're looking for a metronome, you've come to the wrong place."
>
> Charles
>
>
> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
> news:OoAId2M#KHA.4768@newsgroup

>> There is also written that American cars are better than German cars.
>>
>> Do you believe everything which is written without anything which
>> explains why?
>>
>> Take a look at this page which compares timers.
>>
>> http://msdn.microsoft.com/en-us/magazine/cc164015.aspx
>>
>> You can handle them top down like in this page as long as something where
>> they don't work fail.
>>
>> Cor
>>
>>
>>
>> "Charles" <blank@newsgroup> wrote in message
>> news:e7o3vHM#KHA.5916@newsgroup

>>> Hi Cor, good to hear from you.
>>>
>>> I have read that the Forms timer is actually less reliable in terms of
>>> its interval than the other timers, because it is single-threaded.
>>> Coupled with the fact that I want to use this in a service eventually, I
>>> don't think I can use the Forms timer.
>>>
>>> Cheers
>>>
>>> Charles
>>>
>>>
>>> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
>>> news:#3x7yxK#KHA.4308@newsgroup
>>>> Then why not use the standard Windows.Forms.Form.Timer, somehow persons
>>>> want to use the system.timer.timer (the windows service one) or the
>>>> threading timer (who is able to be used in async)
>>>>
>>>> I am glad that you are not writing of the current fourth one the
>>>> dispatcher timer.
>>>>
>>>> People always write about all timers beside the
>>>> windows.forms.form.timer that the others are better, but never tell why
>>>> those are better.
>>>>
>>>> The windows.forms.form timer is at least the most reliable one in most
>>>> situations
>>>>
>>>> Cor
>>>>
>>>> "Charles" <blank@newsgroup> wrote in message
>>>> news:#S6R67E#KHA.1652@newsgroup
>>>>> Hi Dave
>>>>>
>>>>> Yes, I have. It was my understanding that the Timers timer was just a
>>>>> wrapper for the Threading timer. Perhaps not. There doesn't seem to be
>>>>> anything there that suggests it is any more reliable the the threading
>>>>> version. If it doesn't use WM_TIMER messages, do you know how it does
>>>>> work?
>>>>>
>>>>> Thanks
>>>>>
>>>>> Charles
>>>>>
>>>>>
>>>>> "Davej" <galt_57@newsgroup> wrote in message
>>>>> news:a38d2fce-5230-42bd-833c-e9b6748bf691@newsgroup
>>>>>> On May 20, 8:51 am, "Charles" <bl...@newsgroup> wrote:
>>>>>>> [...] Most of the time, each subsequent tick occurs at
>>>>>>> exactly 10 seconds after the previous one, but occasionally
>>>>>>> there can be as much as 20 or 30 seconds between ticks.
>>>>>>>
>>>>>>
>>>>>> You've looked here?
>>>>>>
>>>>>> http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
>>>>>>
 

My Computer

C

Cor Ligthert[MVP]

#15
I forgot to ask you.

How is your American car going at 200 miles an hour?

Cor

"Charles" <blank@newsgroup> wrote in message
news:uRLGmlN#KHA.1652@newsgroup

> Have you actually read the article, Cor? I have. It bears out exactly what
> I said: "System.Windows.Forms.Timer
> If you're looking for a metronome, you've come to the wrong place."
>
> Charles
>
>
> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
> news:OoAId2M#KHA.4768@newsgroup

>> There is also written that American cars are better than German cars.
>>
>> Do you believe everything which is written without anything which
>> explains why?
>>
>> Take a look at this page which compares timers.
>>
>> http://msdn.microsoft.com/en-us/magazine/cc164015.aspx
>>
>> You can handle them top down like in this page as long as something where
>> they don't work fail.
>>
>> Cor
>>
>>
>>
>> "Charles" <blank@newsgroup> wrote in message
>> news:e7o3vHM#KHA.5916@newsgroup

>>> Hi Cor, good to hear from you.
>>>
>>> I have read that the Forms timer is actually less reliable in terms of
>>> its interval than the other timers, because it is single-threaded.
>>> Coupled with the fact that I want to use this in a service eventually, I
>>> don't think I can use the Forms timer.
>>>
>>> Cheers
>>>
>>> Charles
>>>
>>>
>>> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
>>> news:#3x7yxK#KHA.4308@newsgroup
>>>> Then why not use the standard Windows.Forms.Form.Timer, somehow persons
>>>> want to use the system.timer.timer (the windows service one) or the
>>>> threading timer (who is able to be used in async)
>>>>
>>>> I am glad that you are not writing of the current fourth one the
>>>> dispatcher timer.
>>>>
>>>> People always write about all timers beside the
>>>> windows.forms.form.timer that the others are better, but never tell why
>>>> those are better.
>>>>
>>>> The windows.forms.form timer is at least the most reliable one in most
>>>> situations
>>>>
>>>> Cor
>>>>
>>>> "Charles" <blank@newsgroup> wrote in message
>>>> news:#S6R67E#KHA.1652@newsgroup
>>>>> Hi Dave
>>>>>
>>>>> Yes, I have. It was my understanding that the Timers timer was just a
>>>>> wrapper for the Threading timer. Perhaps not. There doesn't seem to be
>>>>> anything there that suggests it is any more reliable the the threading
>>>>> version. If it doesn't use WM_TIMER messages, do you know how it does
>>>>> work?
>>>>>
>>>>> Thanks
>>>>>
>>>>> Charles
>>>>>
>>>>>
>>>>> "Davej" <galt_57@newsgroup> wrote in message
>>>>> news:a38d2fce-5230-42bd-833c-e9b6748bf691@newsgroup
>>>>>> On May 20, 8:51 am, "Charles" <bl...@newsgroup> wrote:
>>>>>>> [...] Most of the time, each subsequent tick occurs at
>>>>>>> exactly 10 seconds after the previous one, but occasionally
>>>>>>> there can be as much as 20 or 30 seconds between ticks.
>>>>>>>
>>>>>>
>>>>>> You've looked here?
>>>>>>
>>>>>> http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
>>>>>>
 

My Computer

C

Charles

#16
I don't remember you like this Cor. Is that really you? What have you done
with the real Cor?


"Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
news:uIUoIpN#KHA.3176@newsgroup

> I forgot to ask you.
>
> How is your American car going at 200 miles an hour?
>
> Cor
>
> "Charles" <blank@newsgroup> wrote in message
> news:uRLGmlN#KHA.1652@newsgroup

>> Have you actually read the article, Cor? I have. It bears out exactly
>> what I said: "System.Windows.Forms.Timer
>> If you're looking for a metronome, you've come to the wrong place."
>>
>> Charles
>>
>>
>> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
>> news:OoAId2M#KHA.4768@newsgroup

>>> There is also written that American cars are better than German cars.
>>>
>>> Do you believe everything which is written without anything which
>>> explains why?
>>>
>>> Take a look at this page which compares timers.
>>>
>>> http://msdn.microsoft.com/en-us/magazine/cc164015.aspx
>>>
>>> You can handle them top down like in this page as long as something
>>> where they don't work fail.
>>>
>>> Cor
>>>
>>>
>>>
>>> "Charles" <blank@newsgroup> wrote in message
>>> news:e7o3vHM#KHA.5916@newsgroup
>>>> Hi Cor, good to hear from you.
>>>>
>>>> I have read that the Forms timer is actually less reliable in terms of
>>>> its interval than the other timers, because it is single-threaded.
>>>> Coupled with the fact that I want to use this in a service eventually,
>>>> I don't think I can use the Forms timer.
>>>>
>>>> Cheers
>>>>
>>>> Charles
>>>>
>>>>
>>>> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
>>>> news:#3x7yxK#KHA.4308@newsgroup
>>>>> Then why not use the standard Windows.Forms.Form.Timer, somehow
>>>>> persons want to use the system.timer.timer (the windows service one)
>>>>> or the threading timer (who is able to be used in async)
>>>>>
>>>>> I am glad that you are not writing of the current fourth one the
>>>>> dispatcher timer.
>>>>>
>>>>> People always write about all timers beside the
>>>>> windows.forms.form.timer that the others are better, but never tell
>>>>> why those are better.
>>>>>
>>>>> The windows.forms.form timer is at least the most reliable one in most
>>>>> situations
>>>>>
>>>>> Cor
>>>>>
>>>>> "Charles" <blank@newsgroup> wrote in message
>>>>> news:#S6R67E#KHA.1652@newsgroup
>>>>>> Hi Dave
>>>>>>
>>>>>> Yes, I have. It was my understanding that the Timers timer was just a
>>>>>> wrapper for the Threading timer. Perhaps not. There doesn't seem to
>>>>>> be anything there that suggests it is any more reliable the the
>>>>>> threading version. If it doesn't use WM_TIMER messages, do you know
>>>>>> how it does work?
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>> Charles
>>>>>>
>>>>>>
>>>>>> "Davej" <galt_57@newsgroup> wrote in message
>>>>>> news:a38d2fce-5230-42bd-833c-e9b6748bf691@newsgroup
>>>>>>> On May 20, 8:51 am, "Charles" <bl...@newsgroup> wrote:
>>>>>>>> [...] Most of the time, each subsequent tick occurs at
>>>>>>>> exactly 10 seconds after the previous one, but occasionally
>>>>>>>> there can be as much as 20 or 30 seconds between ticks.
>>>>>>>>
>>>>>>>
>>>>>>> You've looked here?
>>>>>>>
>>>>>>> http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
>>>>>>>
 

My Computer

C

Cor Ligthert[MVP]

#17
Is it Charles Law?

"Charles" <blank@newsgroup> wrote in message
news:uH1DesN#KHA.420@newsgroup

> I don't remember you like this Cor. Is that really you? What have you done
> with the real Cor?
>
>
> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
> news:uIUoIpN#KHA.3176@newsgroup

>> I forgot to ask you.
>>
>> How is your American car going at 200 miles an hour?
>>
>> Cor
>>
>> "Charles" <blank@newsgroup> wrote in message
>> news:uRLGmlN#KHA.1652@newsgroup

>>> Have you actually read the article, Cor? I have. It bears out exactly
>>> what I said: "System.Windows.Forms.Timer
>>> If you're looking for a metronome, you've come to the wrong place."
>>>
>>> Charles
>>>
>>>
>>> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
>>> news:OoAId2M#KHA.4768@newsgroup
>>>> There is also written that American cars are better than German cars.
>>>>
>>>> Do you believe everything which is written without anything which
>>>> explains why?
>>>>
>>>> Take a look at this page which compares timers.
>>>>
>>>> http://msdn.microsoft.com/en-us/magazine/cc164015.aspx
>>>>
>>>> You can handle them top down like in this page as long as something
>>>> where they don't work fail.
>>>>
>>>> Cor
>>>>
>>>>
>>>>
>>>> "Charles" <blank@newsgroup> wrote in message
>>>> news:e7o3vHM#KHA.5916@newsgroup
>>>>> Hi Cor, good to hear from you.
>>>>>
>>>>> I have read that the Forms timer is actually less reliable in terms of
>>>>> its interval than the other timers, because it is single-threaded.
>>>>> Coupled with the fact that I want to use this in a service eventually,
>>>>> I don't think I can use the Forms timer.
>>>>>
>>>>> Cheers
>>>>>
>>>>> Charles
>>>>>
>>>>>
>>>>> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
>>>>> news:#3x7yxK#KHA.4308@newsgroup
>>>>>> Then why not use the standard Windows.Forms.Form.Timer, somehow
>>>>>> persons want to use the system.timer.timer (the windows service one)
>>>>>> or the threading timer (who is able to be used in async)
>>>>>>
>>>>>> I am glad that you are not writing of the current fourth one the
>>>>>> dispatcher timer.
>>>>>>
>>>>>> People always write about all timers beside the
>>>>>> windows.forms.form.timer that the others are better, but never tell
>>>>>> why those are better.
>>>>>>
>>>>>> The windows.forms.form timer is at least the most reliable one in
>>>>>> most situations
>>>>>>
>>>>>> Cor
>>>>>>
>>>>>> "Charles" <blank@newsgroup> wrote in message
>>>>>> news:#S6R67E#KHA.1652@newsgroup
>>>>>>> Hi Dave
>>>>>>>
>>>>>>> Yes, I have. It was my understanding that the Timers timer was just
>>>>>>> a wrapper for the Threading timer. Perhaps not. There doesn't seem
>>>>>>> to be anything there that suggests it is any more reliable the the
>>>>>>> threading version. If it doesn't use WM_TIMER messages, do you know
>>>>>>> how it does work?
>>>>>>>
>>>>>>> Thanks
>>>>>>>
>>>>>>> Charles
>>>>>>>
>>>>>>>
>>>>>>> "Davej" <galt_57@newsgroup> wrote in message
>>>>>>> news:a38d2fce-5230-42bd-833c-e9b6748bf691@newsgroup
>>>>>>>> On May 20, 8:51 am, "Charles" <bl...@newsgroup> wrote:
>>>>>>>>> [...] Most of the time, each subsequent tick occurs at
>>>>>>>>> exactly 10 seconds after the previous one, but occasionally
>>>>>>>>> there can be as much as 20 or 30 seconds between ticks.
>>>>>>>>>
>>>>>>>>
>>>>>>>> You've looked here?
>>>>>>>>
>>>>>>>> http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
>>>>>>>>
 

My Computer

C

Cor Ligthert[MVP]

#18
Seems to be,

However, you wrote that you had written that you had
heard..........................................

That is so often written about that threading timer without any reason, more
that it seems to sound very elite.

Like I've always have been, I don't like statements which goes around simple
because someone had a dream and thought he had to write about it.

However, if I would have known, it was you, my tone would have been very
different.

:-)

Cor

"Charles" <blank@newsgroup> wrote in message
news:uH1DesN#KHA.420@newsgroup

> I don't remember you like this Cor. Is that really you? What have you done
> with the real Cor?
>
>
> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
> news:uIUoIpN#KHA.3176@newsgroup

>> I forgot to ask you.
>>
>> How is your American car going at 200 miles an hour?
>>
>> Cor
>>
>> "Charles" <blank@newsgroup> wrote in message
>> news:uRLGmlN#KHA.1652@newsgroup

>>> Have you actually read the article, Cor? I have. It bears out exactly
>>> what I said: "System.Windows.Forms.Timer
>>> If you're looking for a metronome, you've come to the wrong place."
>>>
>>> Charles
>>>
>>>
>>> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
>>> news:OoAId2M#KHA.4768@newsgroup
>>>> There is also written that American cars are better than German cars.
>>>>
>>>> Do you believe everything which is written without anything which
>>>> explains why?
>>>>
>>>> Take a look at this page which compares timers.
>>>>
>>>> http://msdn.microsoft.com/en-us/magazine/cc164015.aspx
>>>>
>>>> You can handle them top down like in this page as long as something
>>>> where they don't work fail.
>>>>
>>>> Cor
>>>>
>>>>
>>>>
>>>> "Charles" <blank@newsgroup> wrote in message
>>>> news:e7o3vHM#KHA.5916@newsgroup
>>>>> Hi Cor, good to hear from you.
>>>>>
>>>>> I have read that the Forms timer is actually less reliable in terms of
>>>>> its interval than the other timers, because it is single-threaded.
>>>>> Coupled with the fact that I want to use this in a service eventually,
>>>>> I don't think I can use the Forms timer.
>>>>>
>>>>> Cheers
>>>>>
>>>>> Charles
>>>>>
>>>>>
>>>>> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
>>>>> news:#3x7yxK#KHA.4308@newsgroup
>>>>>> Then why not use the standard Windows.Forms.Form.Timer, somehow
>>>>>> persons want to use the system.timer.timer (the windows service one)
>>>>>> or the threading timer (who is able to be used in async)
>>>>>>
>>>>>> I am glad that you are not writing of the current fourth one the
>>>>>> dispatcher timer.
>>>>>>
>>>>>> People always write about all timers beside the
>>>>>> windows.forms.form.timer that the others are better, but never tell
>>>>>> why those are better.
>>>>>>
>>>>>> The windows.forms.form timer is at least the most reliable one in
>>>>>> most situations
>>>>>>
>>>>>> Cor
>>>>>>
>>>>>> "Charles" <blank@newsgroup> wrote in message
>>>>>> news:#S6R67E#KHA.1652@newsgroup
>>>>>>> Hi Dave
>>>>>>>
>>>>>>> Yes, I have. It was my understanding that the Timers timer was just
>>>>>>> a wrapper for the Threading timer. Perhaps not. There doesn't seem
>>>>>>> to be anything there that suggests it is any more reliable the the
>>>>>>> threading version. If it doesn't use WM_TIMER messages, do you know
>>>>>>> how it does work?
>>>>>>>
>>>>>>> Thanks
>>>>>>>
>>>>>>> Charles
>>>>>>>
>>>>>>>
>>>>>>> "Davej" <galt_57@newsgroup> wrote in message
>>>>>>> news:a38d2fce-5230-42bd-833c-e9b6748bf691@newsgroup
>>>>>>>> On May 20, 8:51 am, "Charles" <bl...@newsgroup> wrote:
>>>>>>>>> [...] Most of the time, each subsequent tick occurs at
>>>>>>>>> exactly 10 seconds after the previous one, but occasionally
>>>>>>>>> there can be as much as 20 or 30 seconds between ticks.
>>>>>>>>>
>>>>>>>>
>>>>>>>> You've looked here?
>>>>>>>>
>>>>>>>> http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
>>>>>>>>
 

My Computer

C

Charles

#19
Hi Cor, yes it's me. I've been off in SQL Server newsgroups for a bit and
Windows Server. Doing lots of databasey stuff. Good to speak with you again.
I'm pleased you remember me.

Cheers

Charles


"Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
news:OAyYARP#KHA.5848@newsgroup

> Seems to be,
>
> However, you wrote that you had written that you had
> heard..........................................
>
> That is so often written about that threading timer without any reason,
> more that it seems to sound very elite.
>
> Like I've always have been, I don't like statements which goes around
> simple because someone had a dream and thought he had to write about it.
>
> However, if I would have known, it was you, my tone would have been very
> different.
>
> :-)
>
> Cor
>
> "Charles" <blank@newsgroup> wrote in message
> news:uH1DesN#KHA.420@newsgroup

>> I don't remember you like this Cor. Is that really you? What have you
>> done with the real Cor?
>>
>>
>> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
>> news:uIUoIpN#KHA.3176@newsgroup

>>> I forgot to ask you.
>>>
>>> How is your American car going at 200 miles an hour?
>>>
>>> Cor
>>>
>>> "Charles" <blank@newsgroup> wrote in message
>>> news:uRLGmlN#KHA.1652@newsgroup
>>>> Have you actually read the article, Cor? I have. It bears out exactly
>>>> what I said: "System.Windows.Forms.Timer
>>>> If you're looking for a metronome, you've come to the wrong place."
>>>>
>>>> Charles
>>>>
>>>>
>>>> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
>>>> news:OoAId2M#KHA.4768@newsgroup
>>>>> There is also written that American cars are better than German cars.
>>>>>
>>>>> Do you believe everything which is written without anything which
>>>>> explains why?
>>>>>
>>>>> Take a look at this page which compares timers.
>>>>>
>>>>> http://msdn.microsoft.com/en-us/magazine/cc164015.aspx
>>>>>
>>>>> You can handle them top down like in this page as long as something
>>>>> where they don't work fail.
>>>>>
>>>>> Cor
>>>>>
>>>>>
>>>>>
>>>>> "Charles" <blank@newsgroup> wrote in message
>>>>> news:e7o3vHM#KHA.5916@newsgroup
>>>>>> Hi Cor, good to hear from you.
>>>>>>
>>>>>> I have read that the Forms timer is actually less reliable in terms
>>>>>> of its interval than the other timers, because it is single-threaded.
>>>>>> Coupled with the fact that I want to use this in a service
>>>>>> eventually, I don't think I can use the Forms timer.
>>>>>>
>>>>>> Cheers
>>>>>>
>>>>>> Charles
>>>>>>
>>>>>>
>>>>>> "Cor Ligthert[MVP]" <Notmyfirstname@newsgroup> wrote in message
>>>>>> news:#3x7yxK#KHA.4308@newsgroup
>>>>>>> Then why not use the standard Windows.Forms.Form.Timer, somehow
>>>>>>> persons want to use the system.timer.timer (the windows service one)
>>>>>>> or the threading timer (who is able to be used in async)
>>>>>>>
>>>>>>> I am glad that you are not writing of the current fourth one the
>>>>>>> dispatcher timer.
>>>>>>>
>>>>>>> People always write about all timers beside the
>>>>>>> windows.forms.form.timer that the others are better, but never tell
>>>>>>> why those are better.
>>>>>>>
>>>>>>> The windows.forms.form timer is at least the most reliable one in
>>>>>>> most situations
>>>>>>>
>>>>>>> Cor
>>>>>>>
>>>>>>> "Charles" <blank@newsgroup> wrote in message
>>>>>>> news:#S6R67E#KHA.1652@newsgroup
>>>>>>>> Hi Dave
>>>>>>>>
>>>>>>>> Yes, I have. It was my understanding that the Timers timer was just
>>>>>>>> a wrapper for the Threading timer. Perhaps not. There doesn't seem
>>>>>>>> to be anything there that suggests it is any more reliable the the
>>>>>>>> threading version. If it doesn't use WM_TIMER messages, do you know
>>>>>>>> how it does work?
>>>>>>>>
>>>>>>>> Thanks
>>>>>>>>
>>>>>>>> Charles
>>>>>>>>
>>>>>>>>
>>>>>>>> "Davej" <galt_57@newsgroup> wrote in message
>>>>>>>> news:a38d2fce-5230-42bd-833c-e9b6748bf691@newsgroup
>>>>>>>>> On May 20, 8:51 am, "Charles" <bl...@newsgroup> wrote:
>>>>>>>>>> [...] Most of the time, each subsequent tick occurs at
>>>>>>>>>> exactly 10 seconds after the previous one, but occasionally
>>>>>>>>>> there can be as much as 20 or 30 seconds between ticks.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> You've looked here?
>>>>>>>>>
>>>>>>>>> http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
>>>>>>>>>
 

My Computer

C

Charles

#20
I'm going to attempt to answer this myself, as I've had an idea.

Rather than try to generate a reliable timer tick, that won't get deferred
when the system gets busy, how about generating a time-out instead. I can
think of two obvious ways of doing it:

1. Put the timed task on it's own thread and go to sleep for the timer tick
interval
2. Also on a separate thread, wait on a handle that never gets set, and set
the timeout to the timer tick interval

I don't know if both methods amount to the same thing, but I would be
interested in people's opinions.

In the first scenario, I spin up a dedicated thread on which I intend to
perform my timed activity at a regular interval. I immediately put the
thread to sleep for my elapsed time, wake up, perform my task and go back to
sleep. This continues forever.

In the second scenario, I create a ManualResetEvent and use WaitOne to wait
for it to be signalled. I set the timeout to my elapsed time again. Each
time the timeout expires I perform my task, and then go back to waiting
again.

In each case, does the technique behave differently from the way a timer
works? In particular, do either or both of them avoid WM_TIMER events? Are
either of these going to give me a more stable and reliable interval,
bearing in mind that I don't mind the interval generated being +/-50%, but I
don't want it to ever be +200%, for example?

I have tried both, and as techniques they work, but testing in the case
where the system is busy and the interval becomes extended is harder to test
empirically.

Charles


"Charles" <blank@newsgroup> wrote in message
news:uYYPRWC#KHA.4316@newsgroup

> I asked a question related to this a little while ago, and thought that
> I'd got my answer, but it has come back to bite me again.
>
> I currently use a System.Threading.Timer to generate a tick every 10
> seconds. At each tick, I execute some code that will take a maximum of 5
> seconds to complete. Most of the time, each subsequent tick occurs at
> exactly 10 seconds after the previous one, but occasionally there can be
> as much as 20 or 30 seconds between ticks.
>
> It was explained, in the previous thread, that the Threading timer relies
> on WM_TIMER messages, which are low down on the priority list. If the
> system gets a bit busy then these message seem to come further apart, so
> my tick interval extends.
>
> What I need is a reliable way to generate a 10 second tick, that still
> works when the system gets a bit busy. I'm running this on Windows Server
> 2003 R2 x64, if that makes any difference.
>
> Does anyone have any ideas?
>
> TIA
>
> Charles
>
>
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)