I've spent some time researching and observing the best practices to avoid blocking the UI thread when attempting to process data on the UI thread. Specifically, I utilize the async/await where I can. However, when populating a DataGrid via Binding, I noticed my UI freezes up after command processing is completed and processing is passed back to the UI.
XAML
<DataGrid ItemsSource="{Binding EndpointModel.DataView}"
AutoGenerateColumns="True" IsReadOnly="True">
</DataGrid>
DataModel command execution:
public async void CommandExecute()
{
...
JsonData = await accessor.GetDataAsync(new Endpoint.Params().Universe(universe)
.WithStart(start)
.WithEnd(end));
// Creates a very large DataTable within my display (30 x 350)
var grid = EndpointModel.CreateDataGrid(JsonData);
EndpointModel.DataView = grid.AsDataView();
}
I've stepped through the code to observe processing times, placed debugger messages and processing seems normal. The await statement takes about 1.5 seconds and the grid processing at the end is a few ms. Yet, when I return from the 'CommandExecute()', it takes about 3-5 seconds before the UI is responsive. The data populates fine - it just takes forever. I don't know if this is expected or whether I have control over this.
thanks.