I have a C# windows service which is running under the NetworkService account. It occasionally needs to print a Chart object which I do by simply calling:
chart.Printing.Print(false); // suppress the Printer Dialog开发者_Go百科
The weird thing is it seems works fine running as a console application.
The only way it will work is if I run the service under a local admin account.
You probably needed access granted for System.Drawing.Printing.PrintingPermission. Reading the documentation, you find the following:
Classes within the System.Drawing.Printing namespace are not supported for use within a Windows service or ASP.NET application or 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.
精彩评论