473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Service timer

I'd like a service to run a function 3 minutes after starting, and then
again every 30 minutes afterward. I'm not too fussy on the times - I just
want it to avoid running the method on the startup event when other services
may not be running yet after a reboot, but still want it to run fairly early
on rather than having to wait the full 30 minutes.

Suggestions on how to accomplish this? Some basic code below...

Thanks in advance.

Mark

*********************************8

public cDcdMain()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call
_timer = new Timer();

_timer.Interval = 1000 * 60 * 30; //30 minutes
_timer.Elapsed += new ElapsedEventHandler(OisOnTimer);
}

// The main entry point for the process
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
cDcdMain() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}

protected void OisOnTimer(Object source, ElapsedEventArgs e)
{
//Do something.
}
Nov 16 '05 #1
1 1478

If you set up service dependencies via the
"ServiceInstaller.ServicesDependedOn" property then you can safely call your
timer handler at startup and every 30 minutes thereafter...

--Richard

"Mark" wrote:
I'd like a service to run a function 3 minutes after starting, and then
again every 30 minutes afterward. I'm not too fussy on the times - I just
want it to avoid running the method on the startup event when other services
may not be running yet after a reboot, but still want it to run fairly early
on rather than having to wait the full 30 minutes.

Suggestions on how to accomplish this? Some basic code below...

Thanks in advance.

Mark

*********************************8

public cDcdMain()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call
_timer = new Timer();

_timer.Interval = 1000 * 60 * 30; //30 minutes
_timer.Elapsed += new ElapsedEventHandler(OisOnTimer);
}

// The main entry point for the process
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
cDcdMain() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}

protected void OisOnTimer(Object source, ElapsedEventArgs e)
{
//Do something.
}

Nov 16 '05 #2

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

Similar topics

2
by: andrewcw | last post by:
I am trying to do a windows service with C#. I am using as a base the VB.NET article in VS, but I thing the WITHEVENTS timer notation is a delegate. Can anyone provide sample code & anh hints. ...
2
by: Jesper Stocholm | last post by:
I have created a simple service which just copies a fil to a new file with a new name on certain intervals (the service implements a timer). I have no problems installing the service and the...
5
by: Dhilip Kumar | last post by:
Hi all, I have developed a windows service using the windows service project template in VS.NET. I have used three controls in the service, a timer, performance counter and a message queue...
2
by: John David Thornton | last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and I've coded it as shown below. However, when I install the service and then start it in MMC, I get a peculiar message: ...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.