.NETGURU
Using System.Drawing.Printing.PrintDocument in Service
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-services' list.


Jeff Widmer
I am trying to print a document from a .net service that I have created. I
can create the System.Drawing.Printing.PrintDocument without a problem but
when I call the System.Drawing.Printing.PrintDocument.Print method, I get
the below two exceptions:

An unhandled exception of type
'System.Runtime.InteropServices.ExternalException' occurred in system.dll
Additional information: Failed to create system events window thread.

An unhandled exception of type 'System.TypeInitializationException' occurred
in system.drawing.dll
Additional information: The type initializer for
"System.Drawing.SafeNativeMethods" threw an exception.

I can print from an aspx page using the same code without a problem. But
when the code is moved into a service I get the exceptions above. Why would
there be a difference? Since the asp.net process is able to print, why
would my service not be able to?

-Jeff

Reply to this message...
 
    
Jeff Widmer
Never mind. I figured it out. I had to allow the service to interact with
the desktop.
In the Services control panel > click on the service > choose properties >
choose the Log On tab > check the box Allow Service to Interact with Desktop

So now I know how to set this property manually to get my service to work,
but how do I set this property in my installer so that when it is installed,
it automatically has access to the desktop?

-Jeff

-----Original Message-----
From: Jeff Widmer [mailto:Click here to reveal e-mail address]
Sent: Wednesday, March 06, 2002 12:24 PM
To: ngfx-services
Subject: [ngfx-services] Using System.Drawing.Printing.PrintDocument in
Service

I am trying to print a document from a .net service that I have created. I
can create the System.Drawing.Printing.PrintDocument without a problem but
when I call the System.Drawing.Printing.PrintDocument.Print method, I get
the below two exceptions:

An unhandled exception of type
'System.Runtime.InteropServices.ExternalException' occurred in system.dll
Additional information: Failed to create system events window thread.

An unhandled exception of type 'System.TypeInitializationException' occurred
in system.drawing.dll
Additional information: The type initializer for
"System.Drawing.SafeNativeMethods" threw an exception.

I can print from an aspx page using the same code without a problem. But
when the code is moved into a service I get the exceptions above. Why would
there be a difference? Since the asp.net process is able to print, why
would my service not be able to?

-Jeff

| [ngfx-services] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-services.asp = JOIN/QUIT

Reply to this message...
 
    
Todd Poston
Unfortunately the one thing about services that are not exposed by .NET is the Interact With Desktop setting. .NET team.. Hello??

I had to do the same thing and ended up pulling code directly from MSDN that uses the Win32 API to perform exactly this. The code is C, of which I know extremely little - but fortunately the code did what I needed it to without much tweaking. I wrapped it up in a console app, threw some argument handling on it, and then just executed the process with the command line arguments I needed (specifying the service I needed to modify) during the install of my application.

I don't have the link handy, but search MSDN on:
OpenSCManager
OpenService
ChangeServiceConfig
SERVICE_WIN32_SHARE_PROCESS | SERVICE_INTERACTIVE_PROCESS

you should be able to find the code pretty easily.

--------------------------------
From: Todd Poston
Reply to this message...
 
 
System.Drawing.Printing.PrintDocument
System.Runtime.InteropServices.ExternalException
System.TypeInitializationException




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification