473,385 Members | 1,856 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,385 software developers and data experts.

Windows service onStart event

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
1 9632
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Fabio Papa | last post by:
I am trying to write a windows service that sends emails to clients at specific times based on information in a sql db. Since this is done for multiple cities, I start a thread for each city and...
8
by: Jerry Camel | last post by:
I want my service to terminate automatically if the specified parameters are invalid. I tried to use a servicecontroller component to attach to the service, but I think that it's failing because...
5
by: Eric | last post by:
Hi I built a service that watch file in a directory. I use a simple filewatcher and add a handler to do something when a file is created. I have the following problem. I can build it, I can...
6
by: acool | last post by:
I managed to get my VB.NET service installed. Now I can't get it to do anything. Tell me how do you debug smething like this if you have to manually install the assembly to run it? the same code...
3
by: Scott H | last post by:
Hello, I'm having a go at writing my first Windows Service in VB.NET and I'm having a problem. I have it installed ok and started the service sucessfully, I can stop it, and restart it fine, the...
4
by: Groundskeeper | last post by:
I can't seem to get a custom UnhandledException handler working for a Windows Service I'm writing in VB.NET. I've read the MSDN and tried various different placements of the AddHandler call, to no...
3
by: John Fred | last post by:
Salve, I have write a service Windows for the remoting. I have a dll Server (OLD COM+) For Configure DLL Server I user Config File Es. <configuration> <system.runtime.remoting>...
12
by: Anil Gupte | last post by:
I wrote my Windows Service first as a regular Windows Exe because it is easier to debug. In that I used AppDir = Application.ExecutablePath.Substring(0,...
3
by: Smithers | last post by:
I'm writing a new Windows Service. During the OnStart event procedure I initialize a few things. If initialization fails, then I do not want for the service to start. What I currently have is...
4
by: emanuelanechei | last post by:
These days i'm creating a windows service in c# which reads some data from a file and saves it in a database. The data in the file changes every minute. I am using FileSystemWatcher object which...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.