简体   繁体   English

Windows注销后如何继续运行C#应用程序

[英]how to keep running C# application after windows log off

I wrote a C# application using RESTful web services. 我使用RESTful Web服务编写了一个C#应用程序。 This application should interact periodically with our server application. 此应用程序应定期与我们的服务器应用程序进 I want this program to keep running in the background even if the user logs out of the computer. 即使用户退出计算机,我希望此程序在后台继续运行。 How can I do this in C#? 我怎么能在C#中做到这一点?

If you don't want your application to stop when the user logs out, then the application can't be running in the user's session (really a WinStation ). 如果您不希望应用程序在用户注销时停止,则应用程序无法在用户的会话中运行(实际上是WinStation )。 That implies your app needs to run in a different session. 这意味着您的应用需要在不同的会话中运行。 The sessions that don't logout are service sessions. 不注销的会话是服务会话。 Run Task Manager and add the Session ID column, and view all processes, and you'll see what I mean. 运行任务管理器并添加会话ID列,并查看所有进程,您将看到我的意思。

So your application needs to run as, or be launched by, a service. 因此,您的应用程序需要作为服务运行或由服务启动。

In addition to the first answer don't keep the service running under the specific user account. 除了第一个答案之外,不要让服务在特定用户帐户下运行。 If you do so then also it won't work if you logged off. 如果你这样做,那么如果你注销它也将无法工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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