Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8623081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:12:03+00:00 2026-06-12T07:12:03+00:00

Apologies if this question sounds a bit generic. I’m just looking for some general

  • 0

Apologies if this question sounds a bit generic. I’m just looking for some general advice about how to go about solving this problem 🙂

Right now I have the following async method which is retrieving a list of files in a custom FileService. This is being fired in the Constructor of a ViewModel.

private async void Construct()
{
   Files = new ObservableCollection<FileViewModel>();
   IList _files = await _fileRepository.GetFiles();
   foreach (File file in _files)
   {
      Files.Add(new FileViewModel(file));
   }
}

As you can probably work out, the async method is retrieving the list of files in 1 step, and then adding them to list (which is the binding source in the UI) to another.

To the user, they will see nothing until the async process has finished, and then after a time they will see all the results at once.

In my head, this defeats the point of async as what I would really want is the results being added as they are being retrieved.

To add another step, I also have a linq query which pulls the first letter of each file to group in to categories. This executes after the foreach loop. How would I go about adding this step also?

Thank you very much for any adivce you can give!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:12:04+00:00Added an answer on June 12, 2026 at 7:12 am

    You’ll have to change your repository at a fundamental level in order to do this. You could return an object which fires events when the items are retrieved and then in the event handler add your object to an INotifyCollectionChanged interface implementation which your control is bound to.

    You could also look into the Reactive Extensions and expose an IObservable<T> interface implementation which when subscribed to, would add the item to the data source (again, implementing INotifyCollectionChanged).

    Regardless of which approach you take, you have to take into account the fact that UI components an only be updated on the thread that they are created on, meaning you have to marshal the call to the UI thread.

    The easiest way to do this to capture the SynchronizationContext using the static Current property before you make any asynchronous calls and then call the Post method with the call to add the item to the INotifyCollectionChanged implementation.

    async/await doesn’t really lend itself to use in this situation; it’s not well-suited for notifications when an operation is complete but to weave continuations on asynchronous operations when they’re complete.

    You might want to reconsider these approaches though. With most LINQ providers, an IQueryable<T> is returned, which derives from IEnumerable<T>. While there certainly can be blocking while the IEnumerable<T> is iterated through, most providers stream the results in rather quick succession, chances are too quick to give you the effect that you want.

    If the LINQ provider is providing them too slowly (large gaps between each iteration), then you can use the ToObservable extension method in the Reactive Framework to enable one of the patterns mentioned above to give you the items to place in your list as soon as you get them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies if this question is a bit obscure, I've been banging my head against
Apologies for this question but I am a bit of a noob with Delphi.
My apologies if this question is too general, as this is my first time
I am newbie to objective-c.So apologies in advance if this question sounds simple.As we
Apologies if this question is a bit daft, but are there any negative repercussions
My apologies if this question has been asked before. I can see there are
All, Apologies in advance - this question might be too open-ended for SO. Anyway...
Apologies if I missed this question already, but I searched and couldn't find it.
(Apologies for the title of this question - I wasn't overly sure how to
My apologies if you think this question is supposed to be on the Math

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.