如何在安装后使Windows服务正常工作? [英] How to make the Windows Service to work after installation?

查看:70
本文介绍了如何在安装后使Windows服务正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我开发了一个Windows服务,我在Windows服务中包含了System.Windows.Forms,我使用了一个消息框。它在Visual Studio 2012中调试应用程序时显示消息框。我通过installutil.exe安装了Windows服务。但是一旦安装完毕,该服务就无法启动。它显示错误消息,因为无法在本地计算机上启动该服务,因为该服务可能未在使用中。当我在服务器管理器中单击日志消息时,我收到以下错误消息服务无法启动。

System.InvalidOperationException:当应用程序未在UserInteractive模式下运行时显示模式对话框或窗体不是有效的操作。指定ServiceNotification或DefaultDesktopOnly样式以显示来自服务应用程序的通知。

在System.Windows.Forms.MessageBox.ShowCore(IWin32Window所有者,字符串文本,字符串标题,MessageBoxButtons按钮,MessageBoxIcon图标,MessageBoxDefaultButton System.Windows.Forms.MessageBox.Show(String text)上的defaultButton,MessageBoxOptions选项,Boolean showHelp)

任何人都可以帮我解决这个问题。 />
在此先感谢

Hi,
I have developed a windows service and i included System.Windows.Forms in windows service and i used one message box. It displays the message box while debugging the application in Visual Studio 2012. I installed the windows service through installutil.exe. But once after installation, the service is not getting started. It shows error message like the service cannot be started on local computer because the service may not be in use. When i clicked the log messages in Server manager i got the following error message Service cannot be started.
System.InvalidOperationException: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
at System.Windows.Forms.MessageBox.ShowCore(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, Boolean showHelp) at System.Windows.Forms.MessageBox.Show(String text)

Any one please help me to resolve this issue.
Thanks in advance

推荐答案

简单。删除消息框。



Win服务不是UI,不需要用户通信。因此,您对消息框的调用是非法的。将一些日志记录放入服务或创建将使用它的服务AND窗体表项目...然后您可以根据服务结果显示消息框。
Simple. Remove the message box.

Win service is not UI and has no need for user communication. Therefore, your call to message box is illegal. Either put some logging into the service or create a service AND windows forms project that will use it...then you can show message box depending on the service result.


这个 [ ^ ]可能有助于您朝着正确的方向前进。
This[^] might help getting you in right direction.


这篇关于如何在安装后使Windows服务正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆