问题描述
在我安装Windows 8完全合法的声明,这样不再工作:
After I installed Windows 8 perfectly legit statement like this doesn't work anymore:
#if DEBUG
Debugger.Launch();
#endif
服务开始忽略那个东西。
是的,我在调试模式下构建项目。
Service starts ignoring that thing.Yes, I am building the project in a debug mode.
如果我将其更改为 Debugger.Break()
- 服务失败,仍然没有对话框
if I change that to a Debugger.Break()
- the service just fails, and still there's no dialog for attaching a debugger.
推荐答案
Debugger.Launch
将启动一个应用程序与可视化GUI。默认情况下,服务不与桌面交互,因此他们所做的任何操作都无法看到。
Debugger.Launch
would launch an application with a visual GUI. By default services do not interact with a desktop and thus anything they do cannot be "seen".
支持与桌面交互已从Windows服务与桌面的交互选项已从某些服务器版本中删除)。我想象他们会继续这种趋势。
Support for interacting with the desktop has slowly been removed from Windows services ("Interact with the desktop" option has been removed from some Server versions for example). I would imagine they've continued this trend.
Windows服务本质上不是GUI应用程序,它们可以在用户登录到桌面之前和之后运行,因此不能一直显示GUI 。一般来说,依赖于在服务中拥有GUI的能力通常不是一个好主意。
Windows Services by nature are not GUI applications, they can run before and after a user logs into a desktop and thus cannot show a GUI all the time. It's not generally a good idea to depend on an ability to have a GUI in a Service.
如果你想做的是调试服务,我建议将其作为一个常规的应用程序,使您可以做诸如启动和调试的事情。无耻的插件:您可以在中找到支持该服务的服务。
If what you want to do is debug a service, I suggest running it as a regular application so that you can do things like Launch and Debug. Shameless plug: you can see Developing Windows Services in Visual Studio for a way to write a service that supports that.
这篇关于Debugger.Launch()在Windows 8上的Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!