Skip to main content
A newer version of this page is available. .
All docs
V22.1

DXWIN0008: Async Event Operations

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

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

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;
    });
}