Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C# windows service takes time to start around 60-65 sec? [closed]

I 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? 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.

like image 507
alice7 Avatar asked Jan 21 '26 01:01

alice7


2 Answers

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.

like image 50
Oded Avatar answered Jan 23 '26 15:01

Oded


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.

like image 24
Vivek Bernard Avatar answered Jan 23 '26 15:01

Vivek Bernard