Skip to main content

DashboardExtractDataSource.UpdateExtractFile(CancellationToken) Method

Updates a data extract file and allows you to cancel the update task through the use of a cancellation token.

Namespace: DevExpress.DashboardCommon

Assembly: DevExpress.Dashboard.v24.1.Core.dll

NuGet Package: DevExpress.Dashboard.Core

Declaration

public void UpdateExtractFile(
    CancellationToken cancellationToken
)

Parameters

Name Type Description
cancellationToken CancellationToken

A CancellationToken object to monitor for cancellation requests.

Remarks

UpdateExtractFile accepts CancellationToken as a parameter and allows you to cancel the update operation in code. You can run the update operation in a separate thread (background task) and cancel this operation after a required period.

The following code snippet cancels the update operation after the set timeout limit expires:

using System.Windows.Forms;
using System.Text;
using System.Threading.Tasks;
using System;
using DevExpress.DashboardCommon;

public partial class Form1 : DevExpress.XtraEditors.XtraForm {
    public Form1() {
        InitializeComponent();
    }
    private void simpleButton1_Click(object sender, System.EventArgs e) {
        CancellationTokenSource tokenSource = new CancellationTokenSource();
        CancellationToken updateExtractCT = tokenSource.Token;
        var updateExtractTask = Task.Factory.StartNew(() => {

            // Connect to the source database and create a data extract.
            DashboardExtractDataSource ExtractDatasource = new DashboardExtractDataSource();
            // ...
            ExtractDatasource.UpdateExtractFile(updateExtractCT);
        });
        try {
            var result = updateExtractTask.Wait(10000);
            if (result)
                MessageBox.Show("Update Completed");
            else {
                MessageBox.Show("Update Canceled");
                tokenSource.Cancel();
            }
        }
        catch (Exception ex) {
            MessageBox.Show(ex.InnerException.Message);
        }
        finally {
            tokenSource.Dispose();
        }
    }
}
See Also