What’s the best way to do some lengthy initialization when a Windows service starts up (or resumes from being paused) without blocking the Service Control Manager?
What’s the best way to do some lengthy initialization when a Windows service starts
Share
You can use a
BackgroundWorkerto perform your lengthy operation in response to the Service.Start event.It’s easy enough to do so in the
OnStart()method of yourServiceBase-derived class. There’s also a reasonable good example on MSDN.Note that you can also subscribe to the
ProgressChangedandRunWorkerCompletedevents, so that you can inform the service control manager of your progress and startup success (or failure).