Does timer interval gets stored anywhere in system or in registry.

A

archana

Hi all,

I want to know about interval of timer.

I am using timer in windows service.I head somewhere that when i set
interval property of timer while setting interval, restart time of Pc
is consider.

My question is if i am using timer in my windows service, is there any
place where interval related information like interval set used by my
application is stored.

My problem is my timer start behaving erractically after 49.7 days. So
instead of restarting PC i reinstall service and problem gets solved.
So i want to know where in system timer related information is stored.

If anyone can shed some light on it then it will be really benefical
for me.

thanks in advance.
 
W

Ward Bekker

Hi Archana,

A possible workaround might be to dispose the Timer instance every day
or so and create a new instance to work with.
 
A

archana

Hi,

thanks for your reply.

But i can't dispose timer object every day as i want my application to
be continusously running.

Can you tell me any other solution.

any help will be truely appreciated.

thanks in advance.
 
C

ChrisM

If all the timer is doing is firing an event on a regular basic, why can't
you dispose it, and create a new instance of the timer which you will link
to the same event again:

Not sure what mechanism you'd use to call it.
-Maybe another timer - possibly then you'd need to re-start the second timer
as well...?
-Maybe you could count the number of times the timer's event fires and call
the method below every 1000 times of whatever seems sensible.

private void ReMakeTimer() // Call this once a day, or whenever.
{
myTimer = new Timer();
myTimer.Enabled = true;
myTimer.Interval = 2000;// of whatever your required interval is
myTimer.Tick +=new EventHandler(myTimer_Tick);//of whatever the method the
timer calls is called...
}
 
M

Morten Wennevik

Hi,

I'm guessing the tick count resets to 0 after 49 days or so in which case
your timer might fire at new times. It might that this is easily solved
by resetting the interval regularly, or dispose and recreate the timer
every now and then.

Note also that you probably should use System.Threading.Timer if you are
using System.Timers.Timer as the latter have been reported to be somewhat
unstable for windows services.
 
A

archana

Hi all,

thanks for reply.

one more question is if i restarted my windows service still timer is
behaving erractically.

Actually after restart my application should start workin properly.

To start application to work properly i have to restart my pc.

can someone tell me reason behind this.

Any help will be truely appreciated.

thanks in advance.
 
C

ChrisM

What exactly do you mean by behaving erratically?
What is the expected timer interval, and what is actually happening?

Could there be somthing else in your program that is firing and maybe
holding up processing, hence causing your timer event to run 'late'?
As it happens after a while, could your program have a memory leak or
somthing?

Strange that it still happens after re-starting the service! Does the
program rely on anything else outside its 'domain' that could be causing a
problem?
 
A

archana

Hi,

Let me elaborate my point.

I have one function which i am executing on elapsed event of timer.
I am expecting this function to be executed once a day so i set
interval to execute it once a day. My application is working properly
say for nearly 30 days.

Suddenly instead of firing elasped event once a day timer getting fired
per mins sometime per seconds also.

I am strange why this is happening. Can you tell me reason behind
this.

Any help will be truely appreciated.


Thanks in advance.
 
S

sloan

Instead of a Timer (dragged onto the form) try a "coded" timer.

Sorry, I only have some old old vb.net code for this one currently.
Outside of "addhandler" ( += new EventHandler) it should be easy enough to
translate)
Private m_doTheWorkTimer As Timer

private sub RegisterTimer()

Dim dueTime As Long

Dim period As Long

' DUE TIME looks like it is the DELAY time .. from the time the service
starts,

' Until this specfic TIMER kicks in. So a Delay Time of 20000

' Will DELAY this timer shooting off until 20 seconds (20000 ms) after the
service starts

dueTime = 20000

period = 5000

' the magic bullet, notice the part after "AddressOf", which is the method

Dim timerHandler = New TimerCallback(AddressOf BeepClass.GoBeep)

m_doTheWorkTimer = New Timer(timerHandler , Me, dueTime, period)

end sub



''Above is the Code Behind of the Windows Service







Public Class BeepClass

Public Shared Sub GoBeep(ByVal state As Object)'' this uses a built in
delegate, with "state as Object" as the generic argument list

Beep()

End Sub



End Class


Also, you may want to read this post (the result authored by me)
http://groups.google.com/groups/sea...imerDelegate+timBeepServiceTimer+&qt_s=Search
 
W

William Stacey [C# MVP]

Use a runonce timer and reset it every time in the callback. This also
gives you change to correct drift or other errors:

private void button24_Click(object sender, EventArgs e)
{
Console.WriteLine("Running a job every 5 seconds.");
System.Threading.Timer timer = null;
timer = new System.Threading.Timer(
delegate(object state)
{
timer.Change(5000, -1);
Console.WriteLine("Job ran at: {0}", DateTime.Now);
}, null, 5000, -1);
}

I did not run this for 40 days, but should work. You could also just create
a new timer.

--
William Stacey [C# MVP]

| Hi,
|
| Let me elaborate my point.
|
| I have one function which i am executing on elapsed event of timer.
| I am expecting this function to be executed once a day so i set
| interval to execute it once a day. My application is working properly
| say for nearly 30 days.
|
| Suddenly instead of firing elasped event once a day timer getting fired
| per mins sometime per seconds also.
|
| I am strange why this is happening. Can you tell me reason behind
| this.
|
| Any help will be truely appreciated.
|
|
| Thanks in advance.
|
| ChrisM wrote:
| > What exactly do you mean by behaving erratically?
| > What is the expected timer interval, and what is actually happening?
| >
| > Could there be somthing else in your program that is firing and maybe
| > holding up processing, hence causing your timer event to run 'late'?
| > As it happens after a while, could your program have a memory leak or
| > somthing?
| >
| > Strange that it still happens after re-starting the service! Does the
| > program rely on anything else outside its 'domain' that could be causing
a
| > problem?
| >
| > | > > Hi all,
| > >
| > > thanks for reply.
| > >
| > > one more question is if i restarted my windows service still timer is
| > > behaving erractically.
| > >
| > > Actually after restart my application should start workin properly.
| > >
| > > To start application to work properly i have to restart my pc.
| > >
| > > can someone tell me reason behind this.
| > >
| > > Any help will be truely appreciated.
| > >
| > > thanks in advance.
| > >
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top