xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xtrareport-dot-printasync-x28-system-dot-string-system-dot-threading-dot-cancellationtoken-x29.md
Asynchronously sends a report to the specified printer.
Namespace : DevExpress.XtraReports.UI
Assembly : DevExpress.XtraReports.v25.2.dll
NuGet Package : DevExpress.Reporting.Core
public Task PrintAsync(
string printerName = "",
CancellationToken token = default(CancellationToken)
)
Public Function PrintAsync(
printerName As String = "",
token As CancellationToken = Nothing
) As Task
| Name | Type | Default | Description |
|---|---|---|---|
| printerName | String | String.Empty |
The name of the printer that should print the report. An empty string specifies the system’s default printer.
| | token | CancellationToken | null |
A cancellation token that the task observes.
|
| Type | Description |
|---|---|
| Task |
A task that sends the report to the printer.
|
This method is equivalent to the Print(String) method but does not lock other actions performed concurrently. For instance, the user interface remains operational while the application prints a report.
Call the PrintAsync method with the await operator.
The optional CancellationToken parameter provides a way to send the cancellation signal to the task. The task monitors the token and stops when it receives the signal. Create a CancellationTokenSource class instance and pass its Token property to the PrintAsync method call. Call the CancellationTokenSource.Cancel method to stop the task.
The code sample below prints a report asynchronously on the system’s default printer. A CancellationTokenSource class instance is used to allow users to interrupt the document printing process if it takes too long.
using DevExpress.XtraReports.UI;
using System;
using System.Threading;
// ...
// Use cancellationTokenSource to allow users to stop the document creation process.
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
// ...
// The cancelButton_Click event handler uses cancellationTokenSource to stop the document creation process.
private void cancelButton_Click(object sender, EventArgs e)
{
cancellationTokenSource.Cancel();
}
// ...
// Create a simple report.
XtraReport report = new XtraReport()
{
Name = "SimpleReport",
Bands = {
new DetailBand() {
Controls = {
new XRLabel() {
Text = "Simple Report"
}
}
}
}
};
// Print the report.
await report.PrintAsync("", cancellationTokenSource.Token);
Imports DevExpress.XtraReports.UI
Imports System.Threading
' ...
' Use cancellationTokenSource to allow users to stop the document creation process.
Private cancellationTokenSource As New CancellationTokenSource()
' ...
' The cancelButton_Click event handler uses cancellationTokenSource to stop the document creation process.
Private Sub cancelButton_Click(ByVal sender As Object, ByVal e As EventArgs)
cancellationTokenSource.Cancel()
End Sub
' ...
Public Async Sub PrintReportAsync()
' Create a simple report.
Dim report = New XtraReport() With {.Name = "SimpleReport"}
Dim band = New DetailBand()
Dim control = New XRLabel() With {.Text = "Simple Report"}
band.Controls.Add(control)
report.Bands.Add(band)
Await report.PrintAsync("", cancellationTokenSource.Token)
End Sub
See Also