1

I'm following the guide at MSDN about downloading the file. So I have made a very simple download:

private async void performDownload_Click(object sender, RoutedEventArgs e)
{
    CancellationTokenSource myCts = new CancellationTokenSource();
    ulong bytesReceived = await DownloadWebFile("myFile.jpg", myCts.Token);
    var forBreakpoint = 5; // set breakpoint here - isn't being hit on a device
    // some further code
}

public async Task<ulong> DownloadWebFile(string fileName, CancellationToken ct)
{
    Uri requestUri = new Uri("http://photojournal.jpl.nasa.gov/jpeg/PIA17555.jpg");
    StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

    BackgroundDownloader downloader = new BackgroundDownloader();
    downloader.Method = "GET";
    downloader.CostPolicy = BackgroundTransferCostPolicy.Always;

    DownloadOperation operation = downloader.CreateDownload(requestUri, file);
    operation.Priority = BackgroundTransferPriority.High;

    await operation.StartAsync().AsTask(ct);
    ulong bytes = operation.Progress.BytesReceived;
    return bytes;  // set breakpoint here - it is being hit
} // here App hangs (only on Device, on emulator works)

The strange situation is that on Emulator everything works, but on the Device (Lumia 820) the code hangs every time when you debug it. If you set the breakpoint at the last line of DownloadWebFile - return bytes, it is being hit, shows correct number of bytes, you can step forward, but only to the bracket. When you try to step forward further, the App hangs (without breakpoints it also hangs). The file as I can see it via IsolatedStorageExplorer is downloaded correctly.

It seems that sometimes program hangs during debugging when trying to step out from async method (thanks @yasen)

2
  • Have you tried to leave only the breakpoint on "var forBreakpoint = 5;"? This happens to me a lot lately - when debugging, I cannot step out of some async methods. As a workaround I just break right after them, once I know they're okay. Commented May 29, 2014 at 6:45
  • @yasen No kidding - you are right. I tried to find out whats wrong with the delay and put the breakpoint inside - and it hang completely. Strange that it behavies different on emulator. I've to edit the question so it isn't missinterpreted - maybe it will help somebody. Also please add an answer, hence it's been solved. Thanks. Commented May 29, 2014 at 7:53

1 Answer 1

2

Lately, when debugging on device, I cannot step out of async methods. If you have that problem, a simple workaround is to just skip these methods once you're sure they work correctly (don't go into them, don't put breakpoints in them).

Also, I haven't had such problems on the emulator, so if it's possible - just debug on it, instead of a device.

I don't know what's causing this, though. I'm pretty sure it used to work at some point.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.