问题
I have a code that is used in an Winforms application. The same code is also used in a Windows Service (exe running as Windows Service). The code grabs the handles to ICONs. But what I found is that, in Task Mangaer (and GDI View), when I ran the Winforms Application the app shows the GDI count. But when I ran the code via Windows Service, the service instance in Task Manager isn't showing any count for GDI. So, does this mean that Windows Service can never hold a GDI handle? If so, how does the code work, that is how is the code that runs on the handle actually working in Windows Service.
回答1:
Services are in fact able to create and use GDI handles in exactly the same way as an ordinary application, except that the display surfaces are not visible to the user.
However, Task Manager is only able to query this information for processes that are in the same session that it is running in, and services always run in a separate session.
So, basically, just a false alarm. :-)
来源:https://stackoverflow.com/questions/44258630/gdi-handles-in-windows-service-vs-interactive-application