Can I use GDI+ in a Service?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If I use GDI+ within a service, what problems can I expect? Why can't GDI+
be used within a service?

http://msdn2.microsoft.com/en-us/library/system.drawing.aspx

"Classes within the System.Drawing namespace are not supported for use
within a Windows or ASP.NET service. Attempting to use these classes from
within one of these application types may produce unexpected problems, such
as diminished service performance and run-time exceptions."
 
Hello

Services in Microsoft Windows are generally console applications that are
designed to run unattended. Therefore, services do not typically have a
user interface. However, the service may require interaction with the user
in some instances. We strongly recommend that services do not run as
interactive services if the services run in an elevated security context
such as SYSTEM.

For the Windows user interface, the desktop is the security boundary. Any
application that is running on the interactive desktop can interact with
any window that is on the interactive desktop, even if that window is not
displayed on the desktop. This behavior is true for every application,
regardless of the security context of the application that creates the
window and regardless of the security context of the application that is
running on the desktop. The Windows message system does not allow an
application to determine the source of a window message.

Because of these design features, any service that opens a window on the
interactive desktop is exposing itself to applications that are executed by
the logged-on user. If the service tries to use window messages to control
its functionality, the logged-on user can disrupt that functionality by
using malicious messages.

So, for security issue, we don't recommend to use user interface or GDI in
a windows service application.

If there is anything unclear, please feel free to let me know.

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
This didn't answer my question. This response says why I shouldn't build
user interaction into a service. That's not what I asked.

I want to know why I shouldn't use System.Drawing in a service. I want to
build a service that creates various drawings or renderings on demand. There
is no interactive user, no windows, no windows messages involved in the
service I want to build. MSDN says not to use System.Drawing in a service.
Why?

Is your answer that MSDN is misleading -- it's just fine to use
System.Drawing in a service as long as I'm not using it for GUI type user
interaction?
 
Hello,

It is not absolute that we cannot use System.Drawing in a Windows Service.
MSDN just warn that we don't recommend you use it in a Windows Service, and
there are may be some unexpected problems if you implement that.

In fact, I indeed saw many problems on using System.Drawing in Windows
Service. There is a solution for such problems: Enable "allow service to
interact with desktop" option of the Windows Service. However, this is not
guaranteed to fix all of the problems. And, as I said before, this may
bring security issue,

If there is anything unclear, please feel free to let us know.


Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Let me repeat once again that I am not implementing any user interactivity in
my service. So I don't understand why there would be a need to enable "allow
service to interact with desktop".

What kinds of problems, not associated with user interactivity, can I expect
by using System.Drawing in a service? And is there a way to work around
those problems?
 
Back
Top