开发者

Realtime progress from Windows service

开发者 https://www.devze.com 2023-02-20 03:09 出处:网络
I\'m working on an application which开发者_JAVA技巧 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 w

I'm working on an application which开发者_JAVA技巧 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?


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


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.

0

精彩评论

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