Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code after await statement is not reached

My Code:

public async Task LoadRecentlyRatedBooks()
{
    RecentlyRatedBooks.Clear();
    try
    {
        var books = await App.CurrentApplication
                             .BookRequests
                             .GetBooksByCategory(BookListCategory.News, 10, 0);
        if (books != null)
        {
            foreach (var book in books)
            {
                var bookViewModel = AddBook(book);

                if (bookViewModel != null)
                {
                    RecentlyRatedBooks.Add(bookViewModel);
                }
            }
        }
    }
    catch(Exception ex)
    {         }
}

public async Task<IEnumerable<Book>> 
         GetBooksByCategory(BookListCategory category, uint limit, uint offset)
{
    var request = CreateBookListURL(category, limit, offset);
    var response = await client.GetResponseAsyncEx<List<Book>>(request);
    return response.Data;
}

I have problem with calling code after await statement. My application reaches the return statement in GetBooksByCategory() method but it never reaches the code after await statement. I tried put breakpoint to catch-block or to line containing if (books != null) but without success. Application never reaches these breakpoints.

Im now using Visual Studio 2010 on Windows 7. There is also Visual Studio 2012 for Desktop installed.

Im sure that my code is working on Windows 8 with Visual Studio 2012 for WP. I wonder why is it not working on Windows 7 with VS 2010.

Link to repository containing my code: https://bitbucket.org/chovik/smartlib-mu-wp

like image 500
Michal Avatar asked Apr 30 '26 00:04

Michal


1 Answers

I've downloaded your .zip solution but it includes dlls in packages got through Nuget, i.e. dlls for targeting .NET 4.0 from VS2012 and runnable from from machine with installed .NET 4.5 only. One also cannot use C# 5.0 extensions for targeting .NET 4.0 from VS 2012 on VS2010 through Async Targeting Pack

In order to use async/await in VS2010 one should not use Nuget or .NET 4.0 upgraded by .NET 4.5 installation (in other words, to have .NET 4.5 installed).

See my answers to:

  • Async CTP not working in VS 2010 SP1
  • Where can I find a TPL dataflow version for 4.0
    with details on how to get and use C# 5.0 extensions in .NET 4.0 (without .NET 4.5/VS2012 installed)
  • Asynchronous Programming with Async and Await

Update:
Once again, citing the answer from "Proper way to use Async with VS 2010 now that VS 2012 is released"

"The Async CTP is the only way to use async in Visual Studio 2010. However, it is not the async that made it into .NET 4.5 / Visual Studio 2012"

There was also a big hot discussion in MSDN forums:

  • "If I target .net 4.0 but run on a machine that has .net 4.5 will .net 4.0 WPF bugs still be there?"
    The title is a little bit misleading since the discussion shifted to impossibility to develop/test .NET 4.0 (om machine without .NET 4.5 installed) from VS2012 and/or from machine with .NET 4.5
like image 167


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!