microsoft / TemplateStudio

Template Studio accelerates the creation of new WinUI 3, WPF, and UWP apps using a wizard-based experience.
Other
2.65k stars 459 forks source link

UI Thread slow response due to the populating of 50k records file in ViewModel.Source observable collection #4688

Open maxzaikin opened 1 year ago

maxzaikin commented 1 year ago

Describe the bug

Dear Friends,

first of I would like to appreciate your framework. It is really amazing tool and realy enjoy it. However I'm facing some wierd spec. effect. I has generated project for DataGrid population with 50 k records from csv file. all works good untill I starting populating ViewModel.Source property this is realy hanging main UI thread. I did moved as much as possible code to the async style but the best i get is slow response UI. Here is how moved my code to the async:

` public async Task<IEnumerable> ProcessCSVData(string csvFilePath, CSVDataService service) {

    Microsoft.UI.Dispatching.DispatcherQueue dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();

    List<ADUserObject> userObjects = new List<ADUserObject>();

    Source.Clear();

    var enumerator = service.SeedCSVFileDataAsync(csvFilePath);

    Source = new ObservableCollection<ADUserObject>();
    await foreach (var item in enumerator.WithCancellation(CancellationToken.None))
    {
        userObjects.Add(item);
        Source.Add(item);
    }

    return userObjects;
}

`

What's intersting is that 50k records gets populated in my List for couple of ms, but once I starting use add thouse to the datagrid observable source property Source.Add(item); the things are getting really bad.

I do understand that the root cause are tons of CollectionUpdate events so I tried to cheat and re-populate Source after I get all data red in my collection as follow: Source = new ObservableCollection<ADUserObject>(userObjects); but once i applied this Observable collection stops receiving any events so it end's up empty no matter what you do. I may guess here that the problem is that by the time when I re-initialize Observable collection property it get's hard coded by the comipler in *.g.cs files so it broke some logic somwehre...

I'm really not claim that this is a bug, but If could help me to improve my logick and get main UI thread responsive while it populates 50k lines in Source prop I would be very apprecaite you.

Best regards, Maks.

To Reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Additional context

No response

Applies to the following platforms:

About your setup