I am using Blazor. Why does the SaveChangesAsync.Wait() method in the code below return no response?
It reflects in the database, the update is done, but it waits forever. Why?
I don't want to use the synchronous SaveChanges() method. I want to know the cause of this problem.
private void Run()
{
try
{
var id = Guid.Parse("5C7B0B3D-08FA-406D-ABCA-18EE33321B55");
var data = DbContext.Set<MyModel>().AsTracking(QueryTrackingBehavior.TrackAll)
.Single(x => x.Id == id);
data.UpdateDate = DateTimeOffset.Now;
}
finally
{
DbContext.SaveChangesAsync(CancellationToken.None)
.Wait(CancellationToken.None); // <-- waiting here forever. Why?
}
}
where called:
private async Task HandleValidSubmit()
{
Run();
await JS.InvokeVoidAsync("swalInfo", null, "Demo");
}
razor.cs:
<EditForm Model="@dto" OnValidSubmit="HandleValidSubmit">...