Back to Devexpress

XtraReport.CreateDocumentAsync(CancellationToken) Method

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xtrareport-dot-createdocumentasync-x28-system-dot-threading-dot-cancellationtoken-x29.md

latest4.3 KB
Original Source

XtraReport.CreateDocumentAsync(CancellationToken) Method

Asynchronously creates a document from an XtraReport to print or display this report.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public Task CreateDocumentAsync(
    CancellationToken token = default(CancellationToken)
)
vb
Public Function CreateDocumentAsync(
    token As CancellationToken = Nothing
) As Task

Optional Parameters

NameTypeDefaultDescription
tokenCancellationTokennull

A cancellation token that the task observes.

|

Returns

TypeDescription
Task

A task that creates a report document.

|

Remarks

This method is equivalent to the CreateDocument() method, but does not lock other actions performed concurrently. For instance, the user interface remains operational while the application creates a report document.

Call the CreateDocumentAsync method with the await operator.

The optional CancellationToken parameter provides a way to send a 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 CreateDocumentAsync method call. Call the CancellationTokenSource.Cancel method to stop the task.

Example

The code sample below creates a report document asynchronously. A CancellationTokenSource class instance is used to allow users to interrupt the document creation process if it takes too long.

csharp
using DevExpress.XtraReports.UI;
using System;
using System.Threading;
// ...
// Use cancellationTokenSource to allow users to stop the document creation process.
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
// ...
async public void CreateReportAsync()
{
    // Create a simple report.
    XtraReport report = new XtraReport() {
        Name = "SimpleReport",
        Bands = {
            new DetailBand() {
                Controls = {
                    new XRLabel() {
                        Text = "Simple Report"
                    }
                }
            }
        }
    };
    // Create a report document.
    await report.CreateDocumentAsync(cancellationTokenSource.Token);
}
vb
Imports DevExpress.XtraReports.UI
Imports System
Imports System.Threading
' ...
' Use cancellationTokenSource to allow users to stop the document creation process.
Private cancellationTokenSource As New CancellationTokenSource()
' ...
Public Async Sub CreateReportAsync()
    ' 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)
    ' Create a report document.
    Await report.CreateDocumentAsync(cancellationTokenSource.Token)
End Sub

See Also

XtraReport Class

XtraReport Members

DevExpress.XtraReports.UI Namespace