从Windows服务打开一个对话窗口 [英] Open a dialog window from a windows service
问题描述
我已经建立在C#中的窗口服务应用程序,弹出在特定的时间间隔一个对话窗口。虽然在Visual Studio中调试,它运作良好。然后,我创建了一个安装设置。但在安装服务后,在不触发弹出对话窗口。
会是怎样的原因以及如何解决这个问题?
I have created a windows service application in C# to popup a dialog window at particular intervals. While debugging in Visual studio, it is working well. Then I created an installation setup. But after installing the service is not firing to popup the dialog window. What will be the reason and how can I fix it?
推荐答案
在会话0中运行服务,这是从隔离在交互式桌面上。你不能从服务显示用户界面。您需要运行一个单独的桌面程序,以显示UI,然后使用IPC服务和桌面程序之间的通信。
Services run in session 0 which is isolated from the interactive desktop. You cannot show UI from a service. You need to run a separate desktop process to show the UI and then use IPC to communicate between the service and the desktop process.
如果您的对话是很简单的你可能使用 WTSSendMessage 。
If your dialog is simple enough you could possibly use WTSSendMessage.
如果你想运行定期代码,那么你可能是一个计划任务,而不是服务更好。
If you want to run code at regular intervals then you may be better off with a scheduled task rather than a service.
这篇关于从Windows服务打开一个对话窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!