CachedReportSourceBase.CreateDocumentAsync() Method

Creates a document from the report specified by the CachedReportSourceBase.Report property, so it can be displayed, printed and exported. Runs the document generation in an individual task asynchronously.

Namespace: DevExpress.XtraPrinting.Caching

Assembly: DevExpress.Printing.v20.2.Core.dll

Declaration

public virtual Task CreateDocumentAsync()
Public Overridable Function CreateDocumentAsync As Task

Returns

Type Description
Task

The task where document generation is performed.

Remarks

To display a report, a Print Preview (Document Viewer) generates a report document internally. However, you may need to obtain a report document without viewing it in a Print Preview, for instance to merge reports, export or print them in code. In this instance, use the CreateDocumentAsync method to generate a report document manually.

using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
// ...
private void button_Click(object sender, EventArgs e) {
    var storage = new MemoryDocumentStorage();
    var report = new MyReport();
    var cachedReportSource = new CachedReportSource(report, storage);
    cachedReportSource.CreateDocumentAsync();
}

This method returns the Task object, since the method performs document generation asynchronously. Use the Task object's members to determine the current document generation status. For instance, use the Wait() method to wait for the task's completion before starting another document generation task. Simultaneous document generation raises the InvalidOperationException exception.

To restart document generation, call the CachedReportSourceBase.StopPageBuilding method and wait until the task where this method operates completes. Then, call the CreateDocumentAsync method again.

You can access the generated document using the members of the object provided by the PrintingSystemBase.Document property of the CachedReportSourceBase's CachedReportSourceBase.PrintingSystem.

See Also