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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:11:48+00:00 2026-06-03T17:11:48+00:00

As per the title. I click my button, and can enter the debugger at

  • 0

As per the title. I click my button, and can enter the debugger at a breakpoint placed on the line calling openPicker.PickSingleFileAsync() – but this call never returns. I can select a file, and click Open, but I never get back into my method to actually do something with that file. This is all in a new Windows Metro ‘Blank Application’ with nothing but a Button and an Image.

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        OpenFile().Wait();
    }

    private async Task OpenFile()
    {
        FileOpenPicker openPicker = new FileOpenPicker();
        openPicker.ViewMode = PickerViewMode.Thumbnail;
        openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
        openPicker.FileTypeFilter.Add(".jpg");
        openPicker.FileTypeFilter.Add(".jpeg");
        openPicker.FileTypeFilter.Add(".png");

        // can break on following line
        var file = await openPicker.PickSingleFileAsync();

        // this line is never reached
        if (file != null)
        {
           // do stuff
        }
    }

This is as per the sample code on MSDN here. I get the same result when I use PickMultipleFilesAsync as well.

Am I missing something obvious?

  • 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-03T17:11:50+00:00Added an answer on June 3, 2026 at 5:11 pm

    You should never mix Wait() and await in a GUI application, because it can very easily lead to deadlocks, exactly as you are experiencing.

    For that matter, you probably shouldn’t use Wait() at all, if you can use await (although there are exceptions: it makes sense to use Wait() in the Main() method of a console application that uses await).

    The problem here is that Wait() blocks your UI thread. After the file picker is done, it schedules the rest of the method to run on the UI thread, but the thread can’t do that because it’s waiting for this operation to complete. So, for this operation to complete, it first has to complete, which is a deadlock.

    The solution here is use await in your event handler too:

    private async void Button_Click_1(object sender, RoutedEventArgs e)
    {
        await OpenFile();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As per the title I have three parts to this question... Is db4o object
As per the title, is this possible? By tri-state, I mean the parent node
Using Visual Studio 2005 As per the title; MSDN and google can't tell me,
As per title. Using native ID's The only thing I can think to do
How can I see the sort button & direction per column in my DataGrid
I apologize if this is a noob question, but I can't seem to figure
As per the title, I have created a custom control. On a certain button
This should be simple, but for reason I can't quite fathom it doesn't work
As per title I need to import, but PG backups is giving me strict
As per title, can there ever be more than 1 \ char in a

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.