views:

203

answers:

2

HI guys, I have designed a windows service in C# and it takes time to start(60-70 sec).I was wondering does it generally take that long to start or it is my code which is taking that much time. I have two threads which runs every 6 seconds and 1 minute.

And if it takes that much time, can somebody tell me why it takes that much time. Not in detail just an overview.

+4  A: 

If your service does alot of work during startup (service.OnStart), it will take a long time to start.

Defer the work to another thread if you want the service to startup immediatly.

This assumes that normal service startup is pretty much immediate.

Oded
Ony thing it does it sets up two timers to run every 6sec and 1 min.And final thread checks the data from DB when the service is started.Do you think this could be reason?
alice7
The final thread checks the data and take action accordingly.Like sending mail etc.
alice7
Could very well be that last thread. Checking the DB and sending email can take a long time.
Oded
Exactly.I just commented out the last thread functionality and it started pretty fast.And when I uncommented out it started slowly as usal.
alice7
Glad my answer helped.
Oded
A: 

Like Oded said,

     protected override void OnStart(string [] args)
  {
System.Threading.Thread workerThread =new System.Threading.Thread(longprocess());
workerThread.start();
  }

private void longprocess()
{
///long stuff
}

Although this will make your service to startup quickly it will not gurantee that longprocess() will be done quickly.

Vivek Bernard