'Why calling an async method gets its body executed sometimes but sometimes not?
I am calling a drop method: It gets called, calls the api alos but sometimes, doesn't update the database even though it hits the line
db.Entry(i).State = EntityState.Modified;
but still doesn't update. It's been a day trying to figure it but can't but when I make the function SYNC instead of ASYNC in the API then it never happens, why?
drop(event: CdkDragDrop<string[]>) {
const group = event.item.data[0];
const items = event.item.data[1];
moveItemInArray(items, event.previousIndex, event.currentIndex);
this.changeDetectorRef.detectChanges();
setTimeout(async () => {
await this.newSvc.updateDo(items.map(i => i.Id))
});
}
newSvc:
updateDo(items) {
let url = `${this.URL}updateDo`;
return this.http.post(url, items).toPromise();
}
Api:
[Route("updateDo")]
[HttpPost]
public async Task<IHttpActionResult> updateDo([FromBody] List<int> args)
{
int dpO = 0;
foreach (var a in args)
{
dpO++;
var i = db.NewSs.SingleOrDefault(n => n.Id == a);
i.DO = dpO;
db.Entry(item).State = EntityState.Modified;
}
await db.SaveChangesAsync();
return Ok();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
