简体   繁体   中英

windows service and my problem

i want to write a windows service app. i'm beginer. now my question is :if the user loging off what event happen OnStop() or OnShutdown()?? after the user logining what happen OnStart() or OnContinue()?? thanks alot.

Windows services are not affected by users logging in or out. They run on their own session. Check this out, especially the "Service Lifetime" section.

none of what you said because a Windows Service does not run in the same Windows Session of the logged in user so it's fully independent and unaffected from user logins.

If you want to better understand the service lifecycle events you could log a message in a text file or use Log4net and log the event name in every method like OnStart, OnStop, OnContinue and so on and then you try to restart the computer and you play a bit with stop/pause/restart from the Services panel from Control Panel.

In general, Services in windows start up when the system starts up and shuts down when the machine is shutting down. The user logging off usually doesn't cause a service to shut down.

If you want something that runs only when the user is logged in and runs interactively in the user session, you should look at the Windows Task Scheduler . You can schedule a task which runs only when the user is logged on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM