Service timer

M

Mark

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(ServicesToRun);
}

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

Guest

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
 

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

Top