需要关于用不可见的 WinForm 应用程序替换 Windows 服务的建议

发布于 2024-10-14 09:04:27 字数 353 浏览 10 评论 0原文

我需要一个后台应用程序来支持我的客户端应用程序,无论主客户端应用程序是否正在运行,它都应该始终在客户端计算机上运行。

Windows 服务是我的第一选择,但我在使用 Windows 服务时面临的问题是:通过主客户端应用程序轻松控制 Windows 服务、为 Windows 服务发布和安装补丁以及在 Windows 服务无法运行时进行故障排除。

因此,我开始考虑 Windows 服务的替代方案,并发现没有可见表单的 Windows 窗体应用程序可以为我做到这一点。这个不可见的应用程序应该随系统启动而启动,并一直运行,完成 Windows 服务要做的所有工作。但在深入开发之前,我想探讨一下这种方法的优缺点。

对这种方法有什么建议/意见吗?

I need a background application to support my client application, which should always run on the client machine regardless of the main client application is running or not.

Windows Service was my first choice but problems I faced with Windows Service were: ease of control over windows service through main client application, release and installation of patches to the windows service and troubleshooting if windows service fails to run.

So, I started thinking for alternatives to the Windows Service and found that a Windows Forms application with NO visible forms can do it for me. This invisible app should start with system startup and keep running all the time, doing all the work that a Windows Service would do. But before I go deeper into the development, I want to explore the pros and cons of this approach.

Any suggestions/comments on this approach?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

謌踐踏愛綪 2024-10-21 09:04:27

你的要求更适合windows服务。 Windows 服务的主要优点是,无论是否有人登录系统,它都会在系统启动后立即启动。

为了解决部署问题,您可以将业务逻辑构建到单独的程序集中,并使用 Windows 服务调用必要的函数。这样您就可以仅部署修改后的程序集。

具有不可见窗体的 Winform 应用程序将无法达到此目的。华泰

Your requirements are more suited for windows service. Main advantage with windows service is that it will start as soon as system comes up, irrespective of anybody is logged into system or not.

To sort out deployment issues, you build your business logic into separate assembly and call the necessary function withing windows service. This way you can deploy just the modified assembly.

Winform application with invisible form will not serve the purpose. HTH

耶耶耶 2024-10-21 09:04:27

那是不可能的。用户模式应用程序必须由用户启动,并且当该用户注销时不会继续运行。这就是 SessionEnding 事件的目的:允许您在用户注销或计算机关闭时正常关闭应用程序。你不能只在系统启动时启动某些东西并让它一直运行。

为此,您需要一个 Windows 服务。但您应该注意,在 Windows Vista 及更高版本下,服务无法直接与用户交互。它们在单独的进程中运行,并且无法显示自己的 UI。从这个问题中并不清楚您的具体需求是什么,但这是 Windows 服务的一个重要限制,值得考虑。正确的设计确实不需要这样做,但显然有很多人对这种新的、更安全的行为感到真正的惊讶。我在 这个问题这个问题

That's not possible. User-mode applications must be started by a user, and will not continue to run when that user logs off. That's the purpose of the SessionEnding event: to allow you to shut down your app gracefully when the user logs off or the computer is shutting down. You can't just start something at system startup and keep it running all the time.

You need a Windows Service for that. But you should be aware that under Windows Vista and later, a service cannot interact directly with the user. They run in a separate process and are restricted from displaying their own UI. It's not clear from the question exactly what your needs are, but this is an important limitation of a Windows Service that is worth considering. A proper design really shouldn't require this, but there are apparently a lot of people to whom this new, more secure behavior is a real surprise. I explain this in more detail in related answers to this question and this other question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文