来自 Windows 服务的实时进度

发布于 2024-10-26 04:13:00 字数 341 浏览 4 评论 0原文

我正在开发一个应用程序,我认为它更适合作为 Windows 服务。我在计划转换它时遇到的唯一问题是它有一个显示活动的窗口。现在我知道从服务中显示 GUI 是不好的做法(在 Win7 中已弃用),所以我的问题是,显示进度的最佳方式是什么?

我的第一个想法是使用 RPC 和 MIDL 的轮询方法,但操作可能会在一两秒内开始和完成,使用轮询会非常不准确。

我对此还有什么其他选择?

谢谢, J

编辑:我的问题更多是关于通信方法,我计划将其分成服务和任务托盘图标,但我想显示一个带有进度条的窗口来显示服务中运行的任务的进度,但轮询也太除非是亚秒,否则很慢,这似乎很浪费,有没有办法将进度推送到任务托盘应用程序?

I'm working on an application which I think would be better suited to being a Windows service. The only issue I have come up against in planning to convert it is that it has a window which displays activity. Now I know it's bad practice (and deprecated in Win7) to show a GUI from a service so my question is, what is the best way to show progress?

My first idea was a polling method using RPC and MIDL but an operation could start and finish in a second or two it would be very inaccurate to using polling.

What are my other options for this?

Thanks,
J

EDIT: My question is more about the communication method, I plan to split it into the service and a task tray icon but I want to display a window with progress bars to show the progress of tasks running in the service but polling would be too slow unless it was sub-second which seems a waste, is there a way to push progress to the task tray app?

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

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

发布评论

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

评论(2

酷遇一生 2024-11-02 04:13:00

创建一个执行该工作的服务,以及一个可选的 GUI 应用程序,该应用程序如果正在运行,则位于系统托盘中并允许您打开一个窗口来观察进度。您可以通过共享内存或命名管道等方式传达进度 - 但请记住,服务在无人登录时运行,因此它决不应该依赖于能够显示进度。

推送机制:

  • 共享内存、互斥体和事件(CreateEvent)。每当服务更新状态时使用 PulseEvent 调用,让系统托盘应用程序等待事件(例如 MsgWaitForMultipleObjects)
  • 命名管道 (CreateNamedPipe) - 这些对于系统托盘应用程序 TCP/UDP 也是可等待的
  • - 避免这种情况,您只会遇到过于热心的防火墙不理解本地主机的概念

Create a service that does the work, and an optional GUI application that, if running, sits in the system tray and allows you to open a window watching the progress. You can communicate the progress over e.g. shared memory or named pipes - but remember that the service is running while noone is logged in, so it should in no way depend on being able to display progress.

Push mechanisms:

  • Shared memory, a mutex and an event (CreateEvent). Use the PulseEvent call whenever the service updates state, have the systray app wait on the event (with e.g. MsgWaitForMultipleObjects)
  • Named pipes (CreateNamedPipe) - These are also waitable for the systray app
  • TCP/UDP - avoid this, you'll just run into overeager firewalls that don't understand the concept of localhost
双手揣兜 2024-11-02 04:13:00

在系统托盘中创建一个图标。当您的服务正在执行其操作时,将图标更改为动画,并更改图标的工具提示(当用户悬停鼠标时)以在气球文本中显示完成的进度。

编辑:再想一想,我可能不会为图标设置动画。只是给它一个不同的外观。把它变成红色,或者别的什么。

Create an icon in the system tray. When your service is doing its thing, change the icon to something animated, and change the tooltip of the icon (when the user hovers the mouse) to display progress complete in the balloon text.

EDIT: On second thought, I'd probably not animate the icon. Just give it a different look. Make it red, or something.

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