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 8620523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:36:08+00:00 2026-06-12T06:36:08+00:00

I have a simple Metro style app that’s giving me an issue with (async

  • 0

I have a simple Metro style app that’s giving me an issue with (async & await).

List<string> fileNames = new List<string>();
...
...
LoadList();
...
...
(Problem) Code that accesses the elements of the fileNames List
...
...

private async void LoadList()
{
    // Code that loops through a directory and adds the 
    // file names to the fileNames List using GetFilesAsync()
}

The problem is that the fileNames List is accessed prematurely – before it is fully loaded with items.
This is because of the async method – the program continues with the next line of code while the async method continues its processing.

How can I access the List after it is fully loaded (After the async method is done)?

Is there a way to accomplish what I’m trying to do without using async in Metro apps ?

  • 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-12T06:36:09+00:00Added an answer on June 12, 2026 at 6:36 am

    You need the calling method to be asynchronous too – and rather than having a variable of fileNames, I’d make the LoadList method return it. So you’d have:

    public async Task ProcessFiles()
    {
        List<string> fileNames = await LoadList();
        // Now process the files
    }
    
    public async Task<List<string>> LoadList()
    {
        List<string> fileNames = new List<string>();
        // Do stuff...
        return fileNames;
    }
    

    This does mean that you need to wait for all the files to be found before you start processing them; if you want to process them as you find them you’ll need to think about using a BlockingCollection of some kind. EDIT: As Stephen points out, TPL Dataflow would be a great fit here too.

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

Sidebar

Related Questions

I have a simple metro style app where I want to drag 16 images
i`m writing simple metro style app in c#. Now i have problem accessing files
I have a simple metro app contains a button, a label and a drop
Using Netbeans 6.8 and metro 2.0 I have written a simple application that makes
I am building a metro style app for windows 8 and I have a
I have a WinRT Metro app (XAML/C#, Windows Release Preview) that manages documents. The
I have simple php validation form that is halfway working. If you leave the
I have simple win service, that executes few tasks periodically. How should I pass
I have simple issue setting a two-way databinding of a checkbox in Silverlight 3.0.
i have simple QStandardItemModel that holds the date to show in QTreeview when i

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.