How to call an async method from a synchronous method in C#?
Hello everyone! I'm a beginner C# developer and I've run into a problem. I have a WPF application where I use Entity Framework to work with a database. I want to use async methods like `ToListAsync()`, `SaveChangesAsync()` to avoid blocking the UI thread.
However, I have an existing synchronous method that is called from an external library (for example, a button event handler that doesn't support async). Inside this method, I need to retrieve data from the database. I'm trying to call the async method `GetCustomersAsync()` as follows:
```csharp
public async Task
- > GetCustomersAsync()
{
using (var db = new MyDbContext())
{
return await db.Customers.ToListAsync();
}
}
public void ButtonClickHandler(obj