0

I have a tiny bit of code which in 'normal debug' just hangs executing "var folder =..."

async Task<StorageFolder> GetAssetsFolderAsync()
    {
        var folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(@"Assets");
        return folder;
    }

I placed two breakpoints as in...

GetFolderAsync

If I break at the first I can Debug.StepOver to the line "return folder". If I use debug.Run instead in goes away and doesn't hit the next breakpoint. The method is called from MainPage_Loaded. Any idea how I can correct this problem. And the weirder thin is that it used to work without a problem and I haven't changed THOSE lines.ie lots of others)

svick
  • 236,525
  • 50
  • 385
  • 514
Paulustrious
  • 609
  • 1
  • 11
  • 17
  • Try this, set a break point on that line inside the task. That works when step into doesn't. – JWP May 05 '17 at 14:36
  • You have to focus on the caller of this code. If it doesn't await the call then you get this behavior. And turtles all the way down, the caller of the caller has to await, etc. The Debug > Windows > Call Stack and Debug > Windows > Tasks debugger windows are your friends. – Hans Passant May 05 '17 at 14:54
  • Are you running the code in Debug or Release mode? – svick May 05 '17 at 17:19

2 Answers2

1

After a long long search I found the answer from Mr Skeet and Mr Cleary. I was blocking the UI thread.

It is explained in far greater detail here:

Call to await GetFileAsync() never returns and app hangs in WinRT app

I don't think I would have thought of it. It was fixed with:

public async static Task<bool> StaticInitializeAsync()
    {
        recordingsFolder = await getRecordingsFolderAsync();
        AssetsFolder = await Statics.InstallationFolder.GetFolderAsync(@"Assets");
        defaultWavFile = await AssetsFolder.GetFileAsync("Default.wav");
        return true;
    }
Community
  • 1
  • 1
Paulustrious
  • 609
  • 1
  • 11
  • 17
0

I believe you get an exception which visual studio handles for you silently.

Try opening the exception settings and make sure it brakes on any exception.

  1. Debug -> Windows -> Exception settings
  2. Mark all the CLR exceptions

EDIT: Also try to catch for AggregateException, these can wrap the true exception when dealing with TPL.

Community
  • 1
  • 1
Slime recipe
  • 2,223
  • 3
  • 32
  • 49