Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DXWIN0008: Async Event Operations

In This Article

Severity: Warning

An async event handler (method) runs synchronously until it reaches the first await expression. The event handler is suspended at this position until the awaited task is complete. In the meantime, the caller of the event handler regains control.

After the task is complete in the background thread, the suspended event handler continues its execution from the await expression. However, a WinForms control has already processed this event. It will ignore event parameters you may set in or after the await expression.

To avoid this issue, set all required event parameters before async method calls.

#Invalid Code

C#
private async void TreeList1_BeforeExpand(object sender, BeforeExpandEventArgs e) {
    e.CanExpand = await GetCanExpandAsync(e.Node.Id); // This line is ignored
}

private Task<bool> GetCanExpandAsync(int nodeID) {
    return Task.Run(async delegate
    {
        await Task.Delay(1000);
        return false;
    });
}

#Valid Code

C#
private void TreeList1_BeforeExpand(object sender, BeforeExpandEventArgs e) {
      e.CanExpand = true;
      await GetCanExpandAsync(e.Node.Id);
}

private Task<bool> GetCanExpandAsync(int nodeID) {
    return Task.Run(async delegate
    {
        await Task.Delay(1000);
        return false;
    });
}