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
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:
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: