Debugger.Launch() on windows service in Windows 8

喜夏-厌秋 提交于 2019-12-30 06:42:09

问题


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.

if I change that to a Debugger.Break() - the service just fails, and still there's no dialog for attaching a debugger.


回答1:


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".

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 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.




回答2:


The secret lies in changing the registry key for the Visual Studio JIT debugger via the following:

reg add "HKCR\AppID\{E62A7A31-6025-408E-87F6-81AEB0DC9347}" /v AppIDFlags /t REG_DWORD /d 8 /f

Before making this change the value on my machine was 0x28. The above changes it to 0x8. In essence it removes the 0x20 flag.

If you search the Microsoft include files (WTypesbase.h) then you find the following:

#define APPIDREGFLAGS_IUSERVER_ACTIVATE_IN_CLIENT_SESSION_ONLY 0x20

Once you make this change then the JIT debugging window is displayed again. I believe that all of this relates to various session 0 security changes made by Microsoft.

Sourced from this post: http://forums.arcgis.com/threads/69842-Debugging-your-SOE-on-Windows-8




回答3:


Is this a Windows Store app or a desktop app?

Try right-clicking on your project (the C# executable project if that's what you have) and selecting "Properties". Then in the left sidebar of options, click "Debug". In the "Start Action" section, check the box for "Do not launch, but debug my code when it starts".

Now you can hit F5 and run Visual Studio with breakpoints in your code, and it will sit and wait for you to fire up the process. Then run your application (outside of Visual Studio), and Visual Studio will attach the debugger.



来源:https://stackoverflow.com/questions/12042054/debugger-launch-on-windows-service-in-windows-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!