could you please help me to understand how to resolve issue of the UI being slow responsive while updating ObservableCollection. The problem is that I'm processing 50K lines file and all works very well untill I start adding these items to the ViewModel's source observable collection.
Even with the fastest possible way it still works very slow
var enumerator = service.SeedCSVFileDataAsync(csvFilePath);
await foreach (var item in enumerator.WithCancellation(CancellationToken.None))
{
userObjects.Add(item);
Source.Add(item); // Here is where the slow begin
}
I understand that adding 50k items to the observable collection generates tons of events which is the root cause of slow response issue however when I'm tryinng to cheat this issue by re-initialize observablecollection with pre-populated collection it stops recieve any events at all.
Source = new ObservableCollection<ADUserObject>(userObjects); after this no data on the screen even if you try to add anything
I think this is because of issues in the generated code and architecture but I can't figure out this by my self, so maybe someone already resolved this issue.
I would be very appreciate you'll if you could help me to understand how to resolve this issue. Again the 50k lines file reads and populates IEnumerable collection with in the few milliseconds with out blocking the ui, the problem appears only when I'm start working with the ObservableCollection.
Appreciate your response in advance, Best regards, Maks.
EDit BTW I just realized that most likely the reason of why this trick isn't work
Source = new ObservableCollection<ADUserObject>(userObjects);
is beacuse compiler do it's own magick with *.g.cs files based on on the framework settings ... did anyone faced already this problem ?