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.
A possible workaround might be to dispose the Timer instance every day
or so and create a new instance to work with.
--
Ward Bekker
"Free .Net 2.0 C# to/from VB.Net Code Converter"
http://www.dotnettaxi.com/Tools/Converter.aspx
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.
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...
}
"archana" <trialpro...@yahoo.com> wrote in message
news:1159967221.4...@m7g2000cwm.googlegroups.com...
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.
On Wed, 04 Oct 2006 12:02:22 +0200, archana <trialpro...@yahoo.com>
wrote:
--
Happy Coding!
Morten Wennevik [C# MVP]
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.
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?
"archana" <trialpro...@yahoo.com> wrote in message
news:1159971475.1...@c28g2000cwb.googlegroups.com...
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.
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/search?hl=en&q=dueTime+timerDelegate+timBeepServiceTimer+&qt_s=Search
"archana" <trialpro...@yahoo.com> wrote in message
news:1159956142....@i42g2000cwa.googlegroups.com...
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]
"archana" <trialpro...@yahoo.com> wrote in message
news:1160028991.8...@k70g2000cwa.googlegroups.com...