Connecting Tech Pros Worldwide Forums | Help | Site Map

Performance : PrintDocument / PrinterSettings / PaperSizes is very VERY **slow**

Robert Hooker
Guest
 
Posts: n/a
#1: Nov 15 '05
Hi,

I'm curious to know if I'm doing something wrong here, or if this is just
mind-numbingly slow for a reason.

In a simple WindowsFormsApplication:

public Form1()
{
// Required for Windows Form Designer support
InitializeComponent();

PrintDocument printDoc = new PrintDocument();
// Add each papersize name (string) to an array
//
// Querying printer for all its papersizes is **Slow**
// - This loop takes about 8 seconds (!!) to execute on my machine for 14
sizes
ArrayList names = new ArrayList();
PrinterSettings printer = printDoc.PrinterSettings;
for( int i=0; i<printer.PaperSizes.Count; i++ )
{
PaperSize psize = printer.PaperSizes[i];
names.Add(psize.PaperName);
}
}

It appears that each call to printer.PaperSizes.xxxxx takes a very VERY long
time. I can speed that loop up by moving the printer.PaperSizes.Count up out
of the loop, but having to do this seems funky.

Am I missing something, or is this stuff just broken for speed?

Rob.



Jon Skeet
Guest
 
Posts: n/a
#2: Nov 15 '05

re: Performance : PrintDocument / PrinterSettings / PaperSizes is very VERY **slow**


Robert Hooker <rhooker@rhooker.com> wrote:

<snip>
[color=blue]
> It appears that each call to printer.PaperSizes.xxxxx takes a very VERY long
> time. I can speed that loop up by moving the printer.PaperSizes.Count up out
> of the loop, but having to do this seems funky.
>
> Am I missing something, or is this stuff just broken for speed?[/color]

You're retrieving printer.PaperSizes twice in each iteration of the
loop. If you fetch the PaperSizes property just once, it speeds things
up considerably. Here's a neat way to do it:

PrinterSettings printer = printDoc.PrinterSettings;
foreach (PaperSize psize in printer.PaperSizes)
{
names.Add(psize.PaperName);
}

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Yan-Hong Huang[MSFT]
Guest
 
Posts: n/a
#3: Nov 15 '05

re: Performance : PrintDocument / PrinterSettings / PaperSizes is very VERY **slow**


Hi Robert,

Thanks for posting in the group.

I noticed that the question is also posted in dotnet.framework group. If
you have time, please check my reply there. I will follow up in that group.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: "Robert Hooker" <rhooker@rhooker.com>
!Subject: Performance : PrintDocument / PrinterSettings / PaperSizes is
very VERY **slow**
!Date: Fri, 26 Sep 2003 09:29:35 -0600
!Lines: 36
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <uzs1TNEhDHA.1692@TK2MSFTNGP09.phx.gbl>
!Newsgroups:
microsoft.public.dotnet.framework,microsoft.public .dotnet.framework.windowsf
orms,microsoft.public.dotnet.languages.csharp
!NNTP-Posting-Host: 12.155.152.130
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
!Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:532 12
microsoft.public.dotnet.languages.csharp:187556
microsoft.public.dotnet.framework:54823
!X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
!
!Hi,
!
!I'm curious to know if I'm doing something wrong here, or if this is just
!mind-numbingly slow for a reason.
!
!In a simple WindowsFormsApplication:
!
!public Form1()
!{
! // Required for Windows Form Designer support
! InitializeComponent();
!
! PrintDocument printDoc = new PrintDocument();
! // Add each papersize name (string) to an array
! //
! // Querying printer for all its papersizes is **Slow**
! // - This loop takes about 8 seconds (!!) to execute on my machine for 14
!sizes
! ArrayList names = new ArrayList();
! PrinterSettings printer = printDoc.PrinterSettings;
! for( int i=0; i<printer.PaperSizes.Count; i++ )
! {
! PaperSize psize = printer.PaperSizes[i];
! names.Add(psize.PaperName);
! }
!}
!
!It appears that each call to printer.PaperSizes.xxxxx takes a very VERY
long
!time. I can speed that loop up by moving the printer.PaperSizes.Count up
out
!of the loop, but having to do this seems funky.
!
!Am I missing something, or is this stuff just broken for speed?
!
!Rob.
!
!
!

Closed Thread