PrintTaskRequest Class

Definition

Contains the request from the system to create a print task. This object is available from the PrintTaskRequestedEventArgs object passed to the PrintTaskRequested event.

public ref class PrintTaskRequest sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class PrintTaskRequest final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class PrintTaskRequest
Public NotInheritable Class PrintTaskRequest
Inheritance
Object Platform::Object IInspectable PrintTaskRequest
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Remarks

The PrintTaskRequest class is used by an app to create a new PrintTask object. A PrintTask object is created in response to the PrintTaskRequested event and it indicates to the system that the app has content to be printed. When creating a PrintTask object using the CreatePrintTask method, the app must provide a name for the PrintTask and a PrintTaskSourceRequestedHandler event handler which is called when the content to be printed is required.

An app should do the minimum amount of work possible in the PrintTaskRequested event handler since only a short amount of time is provided for a response. Wherever possible, the app should simply create a PrintTask and delay any content initialization until the PrintTaskSourceRequestedHandler event handler is called.

If an app needs to perform an asynchronous operation during the PrintTaskRequested handler it must retrieve and use a PrintTaskRequestedDeferral object. Prior to the exit of the event handler, and typically before the asynchronous operation is started, the app must retrieve the PrintTaskRequestedDeferral object by calling the GetDeferral method of the PrintTaskRequest object. When the asynchronous operation completes, the app must call the Complete method of the PrintTaskRequestedDeferral object to signal that the print task request is complete. The call to the Complete method must occur before the Deadline is reached in order for the request to be accepted.

The CreatePrintTask method in PrintTaskRequest can be used to create the print task. Here is a code snippet from the UWP print sample that shows the creation of a print task:

protected virtual void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e)
{
    PrintTask printTask = null;
    printTask = e.Request.CreatePrintTask("C# Printing SDK Sample", sourceRequested =>
    {
        // Print Task event handler is invoked when the print job is completed.
        printTask.Completed += async (s, args) =>
        {
            // Notify the user when the print operation fails.
            if (args.Completion == PrintTaskCompletion.Failed)
            {
                await scenarioPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    MainPage.Current.NotifyUser("Failed to print.", NotifyType.ErrorMessage);
                });
            }
        };

        sourceRequested.SetSource(printDocumentSource);
    });
}

For more information on this and other printing scenarios, see Printing and the UWP print sample.

Properties

Deadline

Gets a DateTime value that indicates how long an app has to respond to the PrintTaskRequested event. If the system has not received a response from the PrintTaskRequested event handler by the time the deadline is reached, then the print task is ignored.

Methods

CreatePrintTask(String, PrintTaskSourceRequestedHandler)

Creates a new PrintTask which indicates that the app has content to be printed.

GetDeferral()

Retrieves the deferral object associated with the PrintTaskRequest. The deferral object is used to handle asynchronous calls in the PrintTaskRequested event handler.

Applies to

See also