473,700 Members | 2,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 WindowsFormsApp lication:

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

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.Printe rSettings;
for( int i=0; i<printer.Paper Sizes.Count; i++ )
{
PaperSize psize = printer.PaperSi zes[i];
names.Add(psize .PaperName);
}
}

It appears that each call to printer.PaperSi zes.xxxxx takes a very VERY long
time. I can speed that loop up by moving the printer.PaperSi zes.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.
Nov 15 '05 #1
2 8271
Robert Hooker <rh*****@rhooke r.com> wrote:

<snip>
It appears that each call to printer.PaperSi zes.xxxxx takes a very VERY long
time. I can speed that loop up by moving the printer.PaperSi zes.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?


You're retrieving printer.PaperSi zes 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.Printe rSettings;
foreach (PaperSize psize in printer.PaperSi zes)
{
names.Add(psize .PaperName);
}

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Hi Robert,

Thanks for posting in the group.

I noticed that the question is also posted in dotnet.framewor k 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" <rh*****@rhooke r.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: <uz************ **@TK2MSFTNGP09 .phx.gbl>
!Newsgroups:
microsoft.publi c.dotnet.framew ork,microsoft.p ublic.dotnet.fr amework.windows f
orms,microsoft. public.dotnet.l anguages.csharp
!NNTP-Posting-Host: 12.155.152.130
!Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
!Xref: cpmsftngxa06.ph x.gbl
microsoft.publi c.dotnet.framew ork.windowsform s:53212
microsoft.publi c.dotnet.langua ges.csharp:1875 56
microsoft.publi c.dotnet.framew ork:54823
!X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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 WindowsFormsApp lication:
!
!public Form1()
!{
! // Required for Windows Form Designer support
! InitializeCompo nent();
!
! 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.Printe rSettings;
! for( int i=0; i<printer.Paper Sizes.Count; i++ )
! {
! PaperSize psize = printer.PaperSi zes[i];
! names.Add(psize .PaperName);
! }
!}
!
!It appears that each call to printer.PaperSi zes.xxxxx takes a very VERY
long
!time. I can speed that loop up by moving the printer.PaperSi zes.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.
!
!
!

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5329
by: Palli Olafs | last post by:
Hi Is it possible to save the PrintDocument as file without using a printer?
2
1739
by: trint | last post by:
I want to do something like this to interrupt the print process (But this does not work because the error is "cannot implicitly conver type void to bool"): while(pd.Print()) { pCounter++; if(printerSettings.Copies == 2) {
0
1336
by: PMGuy | last post by:
Hi guys: We're struggling with a peculiar user request. We're re-implementing an application and a piece of the app allows the users to print a letter and cooresponding envelope to a designated printer with the letter being printed from the "Letterhead" tray and the Envelope printing from the envelop feeder. The Letterhead tray is NOT the default "LETTER" tray.
0
1151
by: toufik | last post by:
I'm using a printDocument object to print a text. How can I set the paper size fomat to LETTER format here is the code that I started, I don't know if its the good direction. System.Drawing.Printing.PrintDocument pr = new System.Drawing.Printing.PrintDocument() pr.DefaultPageSettings.PaperSize=pr.PrinterSettings.PaperSizes(??????) thanks.
2
3350
by: ReidarT | last post by:
I use this code to print a textfile, but it gives me a lot of blank pages. The file contains 9 lines of text. Private strFileName As String = "C:\Sendepost\LoggFil.txt" Private objStreamToPrint As StreamReader Private objPrintFont As Font Private Sub cmdSkrivUt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSkrivUt.Click Dim objPrintDocument As PrintDocument = New PrintDocument
0
1899
by: Madern | last post by:
Good Morning, I'm developing a code that needs to deal with different printer user formats which have to be created on a network driver printer (OKI 321). The big issue I am finding is that the printer doesn't allow me to handle with more than 1 defined format at the same time. We could say it allows me to define just ONE format at a time (and it is going to work with the last format I set), even though the settings
2
28511
by: Steve | last post by:
I'm trying real hard to set the printer resolution for a PrintDocument. It appears that the printer is already set to 300 x 300 dpi, which is JUST what I want. But the Margins and PrintableArea properties of the PageSettings in the Print handler are reporting values that indicate 100 dpi, for example it reports PaperSize as 850, 1100 (8.5" x 11") I'm passing these Rectangle properties into a method that is drawing thinking it's working...
0
1626
by: Fabio | last post by:
Hi all! I have some problems with the PrintDocument under Fw 1.1. I create a new document pd = new PrintDocument And it seems that the pd.PrinterSettings are the ones defined by the default printer.
0
858
by: Academic | last post by:
If I generate a new form by using Start/Printer and Faxes and then right click a printer and chose Properties and then generate a new form, my program then shows the form in PrintDialog (code below) and if selected mPD then contains the correct sizes. But if I do almost the same thing using the code below to open the dialog box and create a new form (rather than selecting the one created as describe above) , the new size do not appear...
0
8647
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9217
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8926
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4659
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2392
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2030
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.