All docs
V21.1
21.2 (EAP/Beta)
21.1
20.2
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

ExcelDataSource.FillAsync(CancellationToken) Method

Populates the ExcelDataSource in an asynchronous manner and uses the cancellationToken parameter to send the cancellation signal.

Namespace: DevExpress.DataAccess.Excel

Assembly: DevExpress.DataAccess.v21.1.dll

Declaration

public Task FillAsync(
    CancellationToken cancellationToken
)

Parameters

Name Type Description
cancellationToken CancellationToken

A cancellation token that the task observes.

Returns

Type Description
Task

A task that populates the data source.

Remarks

Use this method to populate an Excel data source in an individual task asynchronously. Unlike the Fill() method call, FillAsync does not lock other actions performed concurrently. For instance, the user interface remains operational while the data source is populated.

Call the FillAsync method with the await operator.

The 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 FillAsync method call. Call the CancellationTokenSource.Cancel method to stop the task.

Example

The code sample below creates an ExcelDataSource and populates it with data in an asynchronous manner. A CancellationTokenSource class instance is used to allow users to interrupt the data source fill process if it takes too long.

using DevExpress.DataAccess.Excel;
using DevExpress.XtraReports.UI;
using System.Threading;
// ...
// Creates and configures the Excel data source.
ExcelDataSource excelDataSource = new ExcelDataSource();
excelDataSource.Name = "Excel Data Source";
excelDataSource.FileName = "Sales.xlsx";
ExcelWorksheetSettings worksheetSettings = new ExcelWorksheetSettings("SalesPerson", "A1:L2000");
excelDataSource.SourceOptions = new ExcelSourceOptions(worksheetSettings);
// Populates the data source.
await excelDataSource.FillAsync(cancellationTokenSource.Token);
// The cancellationTokenSource allows the users to stop the task.
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
// ...
// Click the button to stop the task.
void cancelButton_Click(object sender, System.EventArgs e)
{
    cancellationTokenSource.Cancel();
}
See Also