Skip to content

Exception when adding items from another thread #185

@daniol

Description

@daniol

Describe the bug
MAUI.DataGrid does not internally handle thread synchronization for updates to its data source. When an item is added to the ObservableCollection from a thread different than the UI thread, the DataGrid does not automatically marshal the change back to the UI thread.
Calling MainThread.BeginInvokeOnMainThread when adding a item to the ItemSource collection solves the problem.

To Reproduce
Steps to reproduce the behavior:

  1. Define a DataGrid with a ItemsSource associated to an ObservableCollection
  2. Add an Item to the ObservableCollection from another thread, for example with Task.Run(() => itemList.Add(x));
  3. A COM exception is thrown when _paginationStepper.IsEnabled is changed
    _paginationStepper.IsEnabled = value > 1;

Expected behavior
Either no exception, or explicitly state on the documentation that calling BeginInvokeOnMainThread is necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions