Question

I've written a service that is to be started automatically. It does some initialization stuff in its OnStart method, including setting up SENS watchers for who logs in.

Will Windows wait until my OnStart method is complete before it allows uers to log in, or is it possible that such a login could happen before my watchers are set up, if the user moves quickly enough?

If the latter is true, can anyone recommend a way to ensure this doesn't happen?

Was it helpful?

Solution

Unfortunately your service is started in parallel with other bootup activities and there is no guarantee that OnStart() will complete prior to someone logging in. This is especially true if OnStart() executes a very lengthy operation, but is not a practical worry if OnStart() completes quickly.

Perhaps you can structure your code to not do too much in OnStart(), and even better, react appropriately to being started after someone has already logged on?

Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top