Threading problem on Win 8.1 - Windows Phone 8 works fine

Jan 31, 2014 at 11:05 AM

I am working on a Win 8.1 app and having some trouble with the latest sqlite winrt version. The following code works without any problem on Windows Phone 8 but freezes on Win 8.1.
Database testDB = new Database(ApplicationData.Current.LocalFolder, databaseName);
await testDB.OpenAsync();

Debug.WriteLine("Step 1");

String query = "SELECT * FROM MyTable";
await testDB.PrepareStatementAsync(query);

Debug.WriteLine("Step 2");

Task<Statement> statementTask = testDB.PrepareStatementAsync(query).AsTask();
statementTask.Wait();  // <-- freezes on Win 8.1

Debug.WriteLine("Step 3");
While this code runs without any problem on Windows Phone 8 it freezes on Windows 8.1 while waiting for statementTask.

I know that it seems not make a lot of sense to use .AsTask() and .Wait(). But this just an example and in the real project it makes sense to run the query synchronously.

However I would like to understand what the problem is. Why does this work on WP and not on Win 8.1?

If I wrap the second statement into a task it completes without any problem on Win 8.1 as well:
Task task = Task.Run(() => {
   Task<Statement> statementTask = testDB.PrepareStatementAsync(query).AsTask();
Of course this implementation does not make a lot of sense either. But why does this one work while the other one fails?