Wednesday 17 March 2021

MVC - Fix Error - Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

 Watch this example on YouTube


 Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.   


To fix it replace

        public ActionResult Index()
        {
            BusinessController b = new BusinessController();
            b.DoSomething();

            return View();
        }

with

using System.Threading.Tasks;

        public async Task< ActionResult> Index()
        {
            BusinessController b = new BusinessController();
            await b.DoSomething();

            return View();
        }



No comments:

Post a Comment