In my Controller I execute another Void Function after the date saved to DB. But sometimes it's show this error :
A second operation started on this context before a previous asynchronous operation completed. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context. Any instance members are not guaranteed to be thread safe.
...and here is a sample of my controller :
public ActionResult All(Chapter chapter){
var x = db.Post.Where(p => p.PostID == chapter.PostID).FirstOrDefault();
if (x == null){return View(chapter);}
counter++;
db.Chapter.Add(chapter);
db.SaveChangesAsync();
savepost(chapter.PostID, counter);
return RedirectToAction("Index");
}
and here is the Void method:
public void savepost(int id,int counter)
{
var article = db.Post.Find(id);
article.LastUpdate = DateTime.Now;
article.ChapterCount = counter;
db.Entry(article).State = EntityState.Modified;
db.SaveChanges();
}
How i can solve this ?