By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,671 Members | 1,403 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,671 IT Pros & Developers. It's quick & easy.

Windows service onStart event

P: n/a
Hi,
I want my service to sit in an endless loop and run a
stored procedure every say, 1 hour.

protected override void OnStart(string[] args)
{

while(1=1)
{
open connection
run sp
close connection

}
The problem is that the service cannot be started and
bombs out. What am doing wrong here?

tia
Nishen
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
All you need to do is just to use a timer. Note, there are 3 timer classes
in .NET. You need one from namespace System.Timers.

private System.Timers.Timer timer;

protected override void OnStart(string[] args)
{
setup timer
start timer
}

Elapsed Event Handler for timer (object sender, ElapsedEventArgs e)
{
open connection
run sp
close connection
restart timer (if was not setup to AutoReset)
}

HTH,

Eliyahu
"Nishen" <na******@nospam.telkom.co.za> wrote in message
news:05****************************@phx.gbl...
Hi,
I want my service to sit in an endless loop and run a
stored procedure every say, 1 hour.

protected override void OnStart(string[] args)
{

while(1=1)
{
open connection
run sp
close connection

}
The problem is that the service cannot be started and
bombs out. What am doing wrong here?

tia
Nishen

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.