

/ Handle the thread apartment state required by the PrintQueue.AddJob method. / Asyncronously, add a batch of XPS documents to the print queue using a PrintQueue.AddJob method. To avoid the Save Output File As dialog when adding a print job to the default queue, ensure that your default printer isn't Microsoft XPS Document Writer, Microsoft Print to PDF, or other print-to-file options. If the queue isn't paused and the printer is working, then a print job will automatically begin printing when it reaches the top of the print queue. Call AddJob(String, String, Boolean) on the print queue reference, passing in a job name, an XPS document path, and the fastCopy parameter.Get a reference to the default PrintQueue of the LocalPrintServer.If the fastCopy parameter value is false, run AddJob(String, String, Boolean) on a thread with single-threaded apartment state.Use Task.Run to avoid blocking the UI thread-since there's no async version of AddJob.This example adds one or more XPS documents to the default queue. For more information, see the Remarks section for AddJob(String, String, Boolean). If you set the fastCopy parameter to false, then the thread that calls the AddJob method must have a single-threaded apartment state, otherwise an exception will be thrown.If you set the fastCopy parameter to true, then XPS validation is skipped and the print job will spool quickly without page-by-page progress feedback.When using the AddJob(String, String, Boolean) method, the value of the fastCopy parameter is a key consideration: Specify whether the XPS document should be validated (by using the fastCopy parameter).Add a new print job for an XML Paper Specification (XPS) document into the default print queue.In the following example, we use the AddJob(String, String, Boolean) method, one of the several overloads of AddJob, to:
