开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜