473,699 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Timer fires a few milliseconds before the actual Due-Time

HL
I am using VS 2005 Beta - C#

Problem: The Timer fires a few milliseconds before the actual Due-Time

Let's say a timer is created in the following manner:
System.Threadin g.Timer m_timer = null;

Let's declare a constant
Int32 m_TimePeriod = 10000;
In the Initialize method:
m_timer = new System.Threadin g.Timer(new TimerCallback(X XXTimerProc));
m_timer.Change( m_TimePeriod, 0);
In WndProc of Form:
Get the current time and store in m_dtCurrentTime

// Change the Due-Time and Period to enable the timer
m_timer.Change( m_TimePeriod, 0);
In the XXXTimerProc:
Check if ( Current Time - m_dtCurrrentTim e) >= m_TimePeriod
{
// Perform some action

::
::

// Change the Due-Time and Period to disable the timer
m_timer.Change( System.Threadin g.Timeout.Infin ite,
System.Threadin g.Timeout.Infin ite);
}
In the WndProc of the Form, the Timer's Change method is called to set the
DueTime to m_TimePeriod. This enables the timer. But the Timer is fired a few
milliseconds before m_TimePeriod. As a result, In the XXXTimerProc, the
condition for checking the difference between the DateTime values fails and
the neccesary actions do not take place.

Is there something wrong that I am doing or Is it a bug in VS 2005 Beta?
Nov 17 '05 #1
9 7278
Hi,

First of all you will NEVER get the event executed exactly as you
especified, winXX is not a real time OS so what is done when the time to
execute the timer is simply generate an event, the handler will be executed
in a thread frm the threadpool.
As you can imagine all this actions take time.

With that said the comparision if ( Current Time - m_dtCurrrentTim e) will
never be exact.
And really don't see the point of the comparision, after all you are calling
this from a timer, what is the point to check the timer elapsed time ?
Why are you calling Change twice , there is where your problem may be.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"HL" <HL@discussions .microsoft.com> wrote in message
news:24******** *************** ***********@mic rosoft.com...
I am using VS 2005 Beta - C#

Problem: The Timer fires a few milliseconds before the actual Due-Time

Let's say a timer is created in the following manner:
System.Threadin g.Timer m_timer = null;

Let's declare a constant
Int32 m_TimePeriod = 10000;
In the Initialize method:
m_timer = new System.Threadin g.Timer(new TimerCallback(X XXTimerProc));
m_timer.Change( m_TimePeriod, 0);
In WndProc of Form:
Get the current time and store in m_dtCurrentTime

// Change the Due-Time and Period to enable the timer
m_timer.Change( m_TimePeriod, 0);
In the XXXTimerProc:
Check if ( Current Time - m_dtCurrrentTim e) >= m_TimePeriod
{
// Perform some action

::
::

// Change the Due-Time and Period to disable the timer
m_timer.Change( System.Threadin g.Timeout.Infin ite,
System.Threadin g.Timeout.Infin ite);
}
In the WndProc of the Form, the Timer's Change method is called to set the
DueTime to m_TimePeriod. This enables the timer. But the Timer is fired a
few
milliseconds before m_TimePeriod. As a result, In the XXXTimerProc, the
condition for checking the difference between the DateTime values fails
and
the neccesary actions do not take place.

Is there something wrong that I am doing or Is it a bug in VS 2005 Beta?

Nov 17 '05 #2
I have also seen this problem and I haven't found an explanation.

See in-line comments:

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:OR******** ******@tk2msftn gp13.phx.gbl...
Hi,

First of all you will NEVER get the event executed exactly as you
especified, winXX is not a real time OS so what is done when the time to
execute the timer is simply generate an event, the handler will be
executed in a thread frm the threadpool.
As you can imagine all this actions take time.

We realize that Windows isn't a real time OS, I would understand if the
timer went off a few milliseconds too late or even seconds late but, the
problem is it's going off too soon. If I set a timer to go off 50,000
milliseconds from now, why would it go off 49,998 milliseconds from now?
The only explanation that I can think of it that the Windows Time service
adjusts the time forward a few milliseconds but that doesn't affect when
timers we fire. That's just a guess.

With that said the comparision if ( Current Time - m_dtCurrrentTim e) will
never be exact.
And really don't see the point of the comparision, after all you are
calling this from a timer, what is the point to check the timer elapsed
time ?
In our case, we have a collection of things that have to happen at specific
times. We walk through that collection and find the nearest time and then
calculate the number of milliseconds between now and the items action time.
Then we set a timer to go off in that number of milliseconds. When the
timer goes off, we walk through the list again expecting to find at least
one item with an action time that has past but, sometimes we don't because
the timer went off a few milliseconds too soon.

In our case, it just means that we reset the time for just a few
milliseconds but I would still like to know what's going on.
John Vottero


Why are you calling Change twice , there is where your problem may be.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"HL" <HL@discussions .microsoft.com> wrote in message
news:24******** *************** ***********@mic rosoft.com...
I am using VS 2005 Beta - C#

Problem: The Timer fires a few milliseconds before the actual Due-Time

Let's say a timer is created in the following manner:
System.Threadin g.Timer m_timer = null;

Let's declare a constant
Int32 m_TimePeriod = 10000;
In the Initialize method:
m_timer = new System.Threadin g.Timer(new TimerCallback(X XXTimerProc));
m_timer.Change( m_TimePeriod, 0);
In WndProc of Form:
Get the current time and store in m_dtCurrentTime

// Change the Due-Time and Period to enable the timer
m_timer.Change( m_TimePeriod, 0);
In the XXXTimerProc:
Check if ( Current Time - m_dtCurrrentTim e) >= m_TimePeriod
{
// Perform some action

::
::

// Change the Due-Time and Period to disable the timer
m_timer.Change( System.Threadin g.Timeout.Infin ite,
System.Threadin g.Timeout.Infin ite);
}
In the WndProc of the Form, the Timer's Change method is called to set
the
DueTime to m_TimePeriod. This enables the timer. But the Timer is fired a
few
milliseconds before m_TimePeriod. As a result, In the XXXTimerProc, the
condition for checking the difference between the DateTime values fails
and
the neccesary actions do not take place.

Is there something wrong that I am doing or Is it a bug in VS 2005 Beta?


Nov 17 '05 #3
why don't you use a thread instead that runs constantly Sleep(0-1) and
distributes tasks as the come to be? Its the most precise way to do it and
is only a tick more difficult...

"John Vottero" <Jo**@mvpsi.com > schrieb im Newsbeitrag
news:uT******** ******@TK2MSFTN GP09.phx.gbl...
I have also seen this problem and I haven't found an explanation.

See in-line comments:

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
wrote in message news:OR******** ******@tk2msftn gp13.phx.gbl...
Hi,

First of all you will NEVER get the event executed exactly as you
especified, winXX is not a real time OS so what is done when the time to
execute the timer is simply generate an event, the handler will be
executed in a thread frm the threadpool.
As you can imagine all this actions take time.

We realize that Windows isn't a real time OS, I would understand if the
timer went off a few milliseconds too late or even seconds late but, the
problem is it's going off too soon. If I set a timer to go off 50,000
milliseconds from now, why would it go off 49,998 milliseconds from now?
The only explanation that I can think of it that the Windows Time service
adjusts the time forward a few milliseconds but that doesn't affect when
timers we fire. That's just a guess.

With that said the comparision if ( Current Time - m_dtCurrrentTim e)
will never be exact.
And really don't see the point of the comparision, after all you are
calling this from a timer, what is the point to check the timer elapsed
time ?


In our case, we have a collection of things that have to happen at
specific times. We walk through that collection and find the nearest time
and then calculate the number of milliseconds between now and the items
action time. Then we set a timer to go off in that number of milliseconds.
When the timer goes off, we walk through the list again expecting to find
at least one item with an action time that has past but, sometimes we
don't because the timer went off a few milliseconds too soon.

In our case, it just means that we reset the time for just a few
milliseconds but I would still like to know what's going on.
John Vottero


Why are you calling Change twice , there is where your problem may be.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"HL" <HL@discussions .microsoft.com> wrote in message
news:24******** *************** ***********@mic rosoft.com...
I am using VS 2005 Beta - C#

Problem: The Timer fires a few milliseconds before the actual Due-Time

Let's say a timer is created in the following manner:
System.Threadin g.Timer m_timer = null;

Let's declare a constant
Int32 m_TimePeriod = 10000;
In the Initialize method:
m_timer = new System.Threadin g.Timer(new TimerCallback(X XXTimerProc));
m_timer.Change( m_TimePeriod, 0);
In WndProc of Form:
Get the current time and store in m_dtCurrentTime

// Change the Due-Time and Period to enable the timer
m_timer.Change( m_TimePeriod, 0);
In the XXXTimerProc:
Check if ( Current Time - m_dtCurrrentTim e) >= m_TimePeriod
{
// Perform some action

::
::

// Change the Due-Time and Period to disable the timer
m_timer.Change( System.Threadin g.Timeout.Infin ite,
System.Threadin g.Timeout.Infin ite);
}
In the WndProc of the Form, the Timer's Change method is called to set
the
DueTime to m_TimePeriod. This enables the timer. But the Timer is fired
a few
milliseconds before m_TimePeriod. As a result, In the XXXTimerProc, the
condition for checking the difference between the DateTime values fails
and
the neccesary actions do not take place.

Is there something wrong that I am doing or Is it a bug in VS 2005 Beta?



Nov 17 '05 #4
"Robert Heuvel" <ro***********@ isopass.com> wrote in message
news:uf******** ******@TK2MSFTN GP12.phx.gbl...
why don't you use a thread instead that runs constantly Sleep(0-1) and
distributes tasks as the come to be? Its the most precise way to do it and
is only a tick more difficult...
I don't see why that would solve the problem. If I calculate the number of
milliseconds until 1:00:00.0000 and do a Sleep(thatNumbe r) I could still
wake from the sleep to find that it's 12:59:59.9773.

"John Vottero" <Jo**@mvpsi.com > schrieb im Newsbeitrag
news:uT******** ******@TK2MSFTN GP09.phx.gbl...
I have also seen this problem and I haven't found an explanation.

See in-line comments:

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
wrote in message news:OR******** ******@tk2msftn gp13.phx.gbl...
Hi,

First of all you will NEVER get the event executed exactly as you
especified, winXX is not a real time OS so what is done when the time to
execute the timer is simply generate an event, the handler will be
executed in a thread frm the threadpool.
As you can imagine all this actions take time.

We realize that Windows isn't a real time OS, I would understand if the
timer went off a few milliseconds too late or even seconds late but, the
problem is it's going off too soon. If I set a timer to go off 50,000
milliseconds from now, why would it go off 49,998 milliseconds from now?
The only explanation that I can think of it that the Windows Time service
adjusts the time forward a few milliseconds but that doesn't affect when
timers we fire. That's just a guess.

With that said the comparision if ( Current Time - m_dtCurrrentTim e)
will never be exact.
And really don't see the point of the comparision, after all you are
calling this from a timer, what is the point to check the timer elapsed
time ?


In our case, we have a collection of things that have to happen at
specific times. We walk through that collection and find the nearest
time and then calculate the number of milliseconds between now and the
items action time. Then we set a timer to go off in that number of
milliseconds. When the timer goes off, we walk through the list again
expecting to find at least one item with an action time that has past
but, sometimes we don't because the timer went off a few milliseconds too
soon.

In our case, it just means that we reset the time for just a few
milliseconds but I would still like to know what's going on.
John Vottero


Why are you calling Change twice , there is where your problem may be.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"HL" <HL@discussions .microsoft.com> wrote in message
news:24******** *************** ***********@mic rosoft.com...
I am using VS 2005 Beta - C#

Problem: The Timer fires a few milliseconds before the actual Due-Time

Let's say a timer is created in the following manner:
System.Threadin g.Timer m_timer = null;

Let's declare a constant
Int32 m_TimePeriod = 10000;
In the Initialize method:
m_timer = new System.Threadin g.Timer(new TimerCallback(X XXTimerProc));
m_timer.Change( m_TimePeriod, 0);
In WndProc of Form:
Get the current time and store in m_dtCurrentTime

// Change the Due-Time and Period to enable the timer
m_timer.Change( m_TimePeriod, 0);
In the XXXTimerProc:
Check if ( Current Time - m_dtCurrrentTim e) >= m_TimePeriod
{
// Perform some action

::
::

// Change the Due-Time and Period to disable the timer
m_timer.Change( System.Threadin g.Timeout.Infin ite,
System.Threadin g.Timeout.Infin ite);
}
In the WndProc of the Form, the Timer's Change method is called to set
the
DueTime to m_TimePeriod. This enables the timer. But the Timer is fired
a few
milliseconds before m_TimePeriod. As a result, In the XXXTimerProc, the
condition for checking the difference between the DateTime values fails
and
the neccesary actions do not take place.

Is there something wrong that I am doing or Is it a bug in VS 2005
Beta?



Nov 17 '05 #5
HL
Hi,

Well, regarding the Change event being called twice: After the timer is
fired, it is disabled. Subsequently, On receiving a message in the WndProc of
the Form, I would like to enable the timer. Hence the Change event is called
twice - once to disable the timer and the next time to enable it.

I can understand if the timer fires a millisconds later than the actual
time. But the problem is that it fires a few milliseconds before the actual
time. Anybody to help out?

Thanks.

"John Vottero" wrote:
"Robert Heuvel" <ro***********@ isopass.com> wrote in message
news:uf******** ******@TK2MSFTN GP12.phx.gbl...
why don't you use a thread instead that runs constantly Sleep(0-1) and
distributes tasks as the come to be? Its the most precise way to do it and
is only a tick more difficult...


I don't see why that would solve the problem. If I calculate the number of
milliseconds until 1:00:00.0000 and do a Sleep(thatNumbe r) I could still
wake from the sleep to find that it's 12:59:59.9773.

"John Vottero" <Jo**@mvpsi.com > schrieb im Newsbeitrag
news:uT******** ******@TK2MSFTN GP09.phx.gbl...
I have also seen this problem and I haven't found an explanation.

See in-line comments:

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
wrote in message news:OR******** ******@tk2msftn gp13.phx.gbl...
Hi,

First of all you will NEVER get the event executed exactly as you
especified, winXX is not a real time OS so what is done when the time to
execute the timer is simply generate an event, the handler will be
executed in a thread frm the threadpool.
As you can imagine all this actions take time.
We realize that Windows isn't a real time OS, I would understand if the
timer went off a few milliseconds too late or even seconds late but, the
problem is it's going off too soon. If I set a timer to go off 50,000
milliseconds from now, why would it go off 49,998 milliseconds from now?
The only explanation that I can think of it that the Windows Time service
adjusts the time forward a few milliseconds but that doesn't affect when
timers we fire. That's just a guess.
With that said the comparision if ( Current Time - m_dtCurrrentTim e)
will never be exact.
And really don't see the point of the comparision, after all you are
calling this from a timer, what is the point to check the timer elapsed
time ?

In our case, we have a collection of things that have to happen at
specific times. We walk through that collection and find the nearest
time and then calculate the number of milliseconds between now and the
items action time. Then we set a timer to go off in that number of
milliseconds. When the timer goes off, we walk through the list again
expecting to find at least one item with an action time that has past
but, sometimes we don't because the timer went off a few milliseconds too
soon.

In our case, it just means that we reset the time for just a few
milliseconds but I would still like to know what's going on.
John Vottero

Why are you calling Change twice , there is where your problem may be.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"HL" <HL@discussions .microsoft.com> wrote in message
news:24******** *************** ***********@mic rosoft.com...
>I am using VS 2005 Beta - C#
>
> Problem: The Timer fires a few milliseconds before the actual Due-Time
>
> Let's say a timer is created in the following manner:
> System.Threadin g.Timer m_timer = null;
>
> Let's declare a constant
> Int32 m_TimePeriod = 10000;
>
>
> In the Initialize method:
> m_timer = new System.Threadin g.Timer(new TimerCallback(X XXTimerProc));
> m_timer.Change( m_TimePeriod, 0);
>
>
> In WndProc of Form:
> Get the current time and store in m_dtCurrentTime
>
> // Change the Due-Time and Period to enable the timer
> m_timer.Change( m_TimePeriod, 0);
>
>
> In the XXXTimerProc:
> Check if ( Current Time - m_dtCurrrentTim e) >= m_TimePeriod
> {
> // Perform some action
>
> ::
> ::
>
> // Change the Due-Time and Period to disable the timer
> m_timer.Change( System.Threadin g.Timeout.Infin ite,
> System.Threadin g.Timeout.Infin ite);
> }
>
>
> In the WndProc of the Form, the Timer's Change method is called to set
> the
> DueTime to m_TimePeriod. This enables the timer. But the Timer is fired
> a few
> milliseconds before m_TimePeriod. As a result, In the XXXTimerProc, the
> condition for checking the difference between the DateTime values fails
> and
> the neccesary actions do not take place.
>
> Is there something wrong that I am doing or Is it a bug in VS 2005
> Beta?
>
>



Nov 17 '05 #6

"HL" <HL@discussions .microsoft.com> wrote in message
news:24******** *************** ***********@mic rosoft.com...
I am using VS 2005 Beta - C#

Problem: The Timer fires a few milliseconds before the actual Due-Time

Let's say a timer is created in the following manner:
System.Threadin g.Timer m_timer = null;

Let's declare a constant
Int32 m_TimePeriod = 10000;
In the Initialize method:
m_timer = new System.Threadin g.Timer(new TimerCallback(X XXTimerProc));
m_timer.Change( m_TimePeriod, 0);
In WndProc of Form:
Get the current time and store in m_dtCurrentTime

// Change the Due-Time and Period to enable the timer
m_timer.Change( m_TimePeriod, 0);
In the XXXTimerProc:
Check if ( Current Time - m_dtCurrrentTim e) >= m_TimePeriod
{
// Perform some action

::
::

// Change the Due-Time and Period to disable the timer
m_timer.Change( System.Threadin g.Timeout.Infin ite,
System.Threadin g.Timeout.Infin ite);
}
In the WndProc of the Form, the Timer's Change method is called to set the
DueTime to m_TimePeriod. This enables the timer. But the Timer is fired a
few
milliseconds before m_TimePeriod. As a result, In the XXXTimerProc, the
condition for checking the difference between the DateTime values fails
and
the neccesary actions do not take place.

Is there something wrong that I am doing or Is it a bug in VS 2005 Beta?

All timers in the Framework are using the System clock as timer source, this
clock has a (system wide default) resolution of x milliseconds (where x is
10 msec. on most X86 based hardware) - that means that the clock changes
(fires) every x (10) msec.
Say you initialize a timer to fire after 10 seconds, and say this happens 2
msec. after the last system clock tick, that means that the timer counts
10000 ticks before it fires, that is after 8 msec. (to the first tick) +
9999 * 10 msec = 9999.8 msec.
When you initialize the timer, your current system time is the time of the
system clock at the last tick, that is the timer initialization time - 2
msec, lets call it t1. When the timer fires the current time is the same as
the time of the system clock, that is 10000 clock ticks after t1 or exactly
10000 msec. That means that your timer interval will always be up to x - 1
msec. less than the wanted interval.
What you could do to solve your problem (though I don't get why you are
doing this) is correct the start time by adding the clock interval to the
start time t1 (your m_dtCurrentTime ).

Willy.

Nov 17 '05 #7
"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:uS******** ******@TK2MSFTN GP15.phx.gbl...
[snip]
All timers in the Framework are using the System clock as timer source,
this clock has a (system wide default) resolution of x milliseconds (where
x is 10 msec. on most X86 based hardware) - that means that the clock
changes (fires) every x (10) msec.
Say you initialize a timer to fire after 10 seconds, and say this happens
2 msec. after the last system clock tick, that means that the timer counts
10000 ticks before it fires, that is after 8 msec. (to the first tick) +
9999 * 10 msec = 9999.8 msec.
When you initialize the timer, your current system time is the time of the
system clock at the last tick, that is the timer initialization time - 2
msec, lets call it t1. When the timer fires the current time is the same
as the time of the system clock, that is 10000 clock ticks after t1 or
exactly 10000 msec. That means that your timer interval will always be up
to x - 1 msec. less than the wanted interval.
What you could do to solve your problem (though I don't get why you are
doing this) is correct the start time by adding the clock interval to the
start time t1 (your m_dtCurrentTime ).


Thanks. Is there a way to get the clock interval? Is it a fairly safe bet
that the clock interval will always be <= 10ms?

Nov 17 '05 #8

"John Vottero" <Jo**@mvpsi.com > wrote in message
news:OP******** ******@TK2MSFTN GP12.phx.gbl...
"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:uS******** ******@TK2MSFTN GP15.phx.gbl...

[snip]

All timers in the Framework are using the System clock as timer source,
this clock has a (system wide default) resolution of x milliseconds
(where x is 10 msec. on most X86 based hardware) - that means that the
clock changes (fires) every x (10) msec.
Say you initialize a timer to fire after 10 seconds, and say this happens
2 msec. after the last system clock tick, that means that the timer
counts 10000 ticks before it fires, that is after 8 msec. (to the first
tick) + 9999 * 10 msec = 9999.8 msec.
When you initialize the timer, your current system time is the time of
the system clock at the last tick, that is the timer initialization
time - 2 msec, lets call it t1. When the timer fires the current time is
the same as the time of the system clock, that is 10000 clock ticks after
t1 or exactly 10000 msec. That means that your timer interval will always
be up to x - 1 msec. less than the wanted interval.
What you could do to solve your problem (though I don't get why you are
doing this) is correct the start time by adding the clock interval to the
start time t1 (your m_dtCurrentTime ).


Thanks. Is there a way to get the clock interval? Is it a fairly safe
bet that the clock interval will always be <= 10ms?


Yep, using PInvoke...

[DllImport("kern el32.dll")]
extern static int GetSystemTimeAd justment(out uint lpTimeAdjustmen t,
out uint lpTimeIncrement , out bool lpTimeAdjustmen tDisabled);

....
GetSystemTimeAd justment(out adjustment,
out clockInterval,
out adjustmentDisab led );

clockInterval returns the clock interval in 100 nsec. units. Divide this
number by 1000 to get the msec. timer interval.

Willy.
Nov 17 '05 #9
HL
Thanks Willy. The solution was very nicely explained.

"Willy Denoyette [MVP]" wrote:

"John Vottero" <Jo**@mvpsi.com > wrote in message
news:OP******** ******@TK2MSFTN GP12.phx.gbl...
"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:uS******** ******@TK2MSFTN GP15.phx.gbl...

[snip]

All timers in the Framework are using the System clock as timer source,
this clock has a (system wide default) resolution of x milliseconds
(where x is 10 msec. on most X86 based hardware) - that means that the
clock changes (fires) every x (10) msec.
Say you initialize a timer to fire after 10 seconds, and say this happens
2 msec. after the last system clock tick, that means that the timer
counts 10000 ticks before it fires, that is after 8 msec. (to the first
tick) + 9999 * 10 msec = 9999.8 msec.
When you initialize the timer, your current system time is the time of
the system clock at the last tick, that is the timer initialization
time - 2 msec, lets call it t1. When the timer fires the current time is
the same as the time of the system clock, that is 10000 clock ticks after
t1 or exactly 10000 msec. That means that your timer interval will always
be up to x - 1 msec. less than the wanted interval.
What you could do to solve your problem (though I don't get why you are
doing this) is correct the start time by adding the clock interval to the
start time t1 (your m_dtCurrentTime ).


Thanks. Is there a way to get the clock interval? Is it a fairly safe
bet that the clock interval will always be <= 10ms?


Yep, using PInvoke...

[DllImport("kern el32.dll")]
extern static int GetSystemTimeAd justment(out uint lpTimeAdjustmen t,
out uint lpTimeIncrement , out bool lpTimeAdjustmen tDisabled);

....
GetSystemTimeAd justment(out adjustment,
out clockInterval,
out adjustmentDisab led );

clockInterval returns the clock interval in 100 nsec. units. Divide this
number by 1000 to get the msec. timer interval.

Willy.

Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1864
by: David | last post by:
Hi There! I'm using Timer control to record how long my application perform certain tasks. However, apparently Timer control is not doing its' job (i.e. Not firing Tick event) while my application is busy. So even if my application took 2 mins, the label that is used to show the number of seconds elapsed will still say "2 seconds".
2
4568
by: Ryan Moore | last post by:
is there any way to get a more accurate version of the timer? Basically what I need it to do something every 33 milliseconds, but for some reason, setting the timer.Interval=33 does not ensure that my event happens every 33ms (probably because it takes a while to do the event) Is there any sort of a "Wait" method that allows me to pause for a certain number of milliseconds? thnx
6
2875
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a TimerState object similar to the example in the System.Threading.Timer documentation. The method which handles the timer events, among other things, periodically calls a method in this TimerState object which raises an event to the startup form,...
6
6147
by: whtinkm | last post by:
Hi, All Recently, my project need some code like following: using System; using System.Threading; namespace MyTimerTest { class Class1 {
6
2052
by: Antti Laakso | last post by:
Hi i have function like above Public Sub halytystutkinta() Dim ds As New DataSet ds = dl2.HaeHalytys() Dim onkohal As Int16 onkohal = ds.Tables(0).Rows(0).Item("onkohalytys") halid = ds.Tables(0).Rows(0).Item("halid")
5
2184
by: csgraham74 | last post by:
HI all, I want to implement this scenario: I need my ASP.NET website to check a SQL table every 30 seconds and if there is a change to display a message to user. I have created a panel control (pnlMessage) and placed the message on it also made it default to visible = false. I have placed a Timer control on my ASP.NET Web Form and set its Interval = 30000 (30 seconds) it fires ok every 30 seconds and the code executes it hits the line...
2
304
by: Myo Zaw | last post by:
hi, i have a windows service which is checking to the desire URL and check back its httpwebresponse data. and, i save the result in a log file insdie local drive. i use a timer to trigger my service's function that check to my desire URL response. the problem is with that timer. since my timer's data type is double, my friend suggest that if it reach to its maximum value my service will get error or it will stop. he had faced with that...
8
1530
by: TheMadHatter | last post by:
Yello, Quick Q: I created a windows service that changes some data every (approx) 1sec, but currently it is using a loop on a separate thread that uses Thread.Sleep(1000). Is that bad programming tecnique? Should I be using a timer instead? Is there any good advantages to the way it is done? A side Q:
10
4286
by: igor | last post by:
I have recently discovered that the system.Timers.Timer from.Net Framework v1.1 is not reliable when used on Windows 2003 server. When incorporated into a Windows Service, the timer_elapsed event will stop executing after 30 to 40 days. After learning this, I found the same issue had been documented in the the System.Threading.Timer class as well. This limits my options for having a timer based windows service using the .net framework....
8
2662
by: =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post by:
I have a Timer that I set to go off once a day, but it frequently fails! In order to debug I would like to be able to check, at any moment, whether the Timer is enabled and when it will next Elapse. Is there any way -- whether in my code, or in the O/S -- to determine when a Timer is scheduled to Elapse?
0
8704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9187
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9053
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8936
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.