来自 Windows 服务的实时进度
我正在开发一个应用程序,我认为它更适合作为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个执行该工作的服务,以及一个可选的 GUI 应用程序,该应用程序如果正在运行,则位于系统托盘中并允许您打开一个窗口来观察进度。您可以通过共享内存或命名管道等方式传达进度 - 但请记住,服务在无人登录时运行,因此它决不应该依赖于能够显示进度。
推送机制:
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:
在系统托盘中创建一个图标。当您的服务正在执行其操作时,将图标更改为动画,并更改图标的工具提示(当用户悬停鼠标时)以在气球文本中显示完成的进度。
编辑:再想一想,我可能不会为图标设置动画。只是给它一个不同的外观。把它变成红色,或者别的什么。
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.