dotnet / dotnet/efcore

SQLite: Make async methods call Task.Yield()

Open
#28,279 16 comments 9 reactions 0 assignees View on GitHub
area-adonet-sqlite customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

It's not good that SQLite's async methods are not real async (tested on v 6.0.6), since they don't yield back to the current context. These methods just work as synchronous methods. It's not good for tests and for Blazor apps that are using SQLite as a db. In Blazor with real async methods UI updates fine, but with methods from SQLite UI doesn't update as it's exptected, so I had to call extra `Task.Yield() ` method:
```cs
private async Task AddProduct()
{
_message = "Adding product..."; //this message is showing inside Blazor component
await Task.Yield(); //I have to call this all the time before call dbContext's pseudo-async methods to properly update UI
await DbContext.Products.AddAsync(product);
await DbContext.SaveChangesAsync();
_message = "Product is added";
}
```

I suggest to add properly async IO support, or at least add call of `await Task.Yield()` inside all pseudo-async SQLite-methods just for asynchronously yield back to the current context when awaited as a real async method does.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.