Ok i have been though many topics on this site and this whole async thing still confuses me so im going to keep it simple.
I Have a ActionMethod on a controller.
public async Task<ActionResult> Index()
{
try
{
throw new Exception("test");
}
catch (Exception ex)
{
new MD_Log().LogError();
}
return View();
}
My ErrorLog function is async itself
// adds a new error log
public async Task LogError()
{
Thread.Sleep(10000);
// add a record to the error table
using (DB db = new DB())
{
// SomeCode
await db.SaveChangesAsync();
}
}
I throw a new exception on my controller, the LogError() method gets called and i pause the execution of the log function for 10 seconds.
I do not want to wait for the LogError() function to complete because my users do not need to wait for that, so i leave out the await keyword from the new MD_Log().LogError() function within my controller action.
Now if i add a break point on the return View(); should that break point not be hit first before the await db.SaveChangesAsync() gets hit?
I am not adding the await keyword and i am adding a 10 second pause to the LogError function.
Whats going on here? this seems synchronous to me. How could i return to view while the LogError() function is still running in the background?