BACKGROUND: I'm trying to make an async Task in my MVCcontroller class that will call a method in my modelclass which will insert a bunch of data into multiple sql tables using an already existing sql table. As the frontend will time out when called from there if it's not async (It makes millions of operations) I wish to use this controller task to run async operations. Once it is done with it's operations it should write to a file that I will see and understand that all computations are done. Yes, there might be smarter ways of calling the Task but that's for later, for now I just wish to figure out how to do the async set-up.
PROBLEM/QUESTION: Controller says that the await_part can not await void, can I just return something like Json(success)? Or how do I do this set up? I'm kind of a rookie.
In the model method I wish to look at the existing sql-table and use it to create more sql-tables that I will persist in the database, not really interested in sending anything back besides something that says "I'm done with the calculations".
Controller calling the model method that will perform actions.
public async Task GenerateBackEndCalculations(string sqlTableName)
{
if (nameOfTable == "sqlTableName")
{
await _context.BackEndCalculations();
}
}
the model method that looks like this
public void BackEndCalculations ()
{
Do something here, and maybe return something if I have to???
}
Task.Run(()=>BackEndCalculations()).Wait();Wrapping already asynchronous method withTask.Runis waste of resources(threads) and you will loose all benefits of asynchronous methods.