Debugger.Launch() on windows service in Windows 8

后端 未结 3 784
无人共我
无人共我 2021-01-05 13:16

After I installed Windows 8 perfectly legit statement like this doesn\'t work anymore:

#if DEBUG
    Debugger.Launch();
#endif

Service star

相关标签:
3条回答
  • 2021-01-05 13:39

    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.

    Do Not Launch option in Properties

    0 讨论(0)
  • 2021-01-05 13:47

    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

    0 讨论(0)
  • 2021-01-05 13:57

    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.

    0 讨论(0)
提交回复
热议问题