How do I get my jquery methods to call my mvc controller and my mvc controller to do two things at once?
Jquery code works fine. He just calls methods and keeps moving as I want.
$(document).ready(function () { console.log("1"); getADsad(); console.log("2"); lala(); console.log("3"); }); function getADsad() { $.ajax({ url: '/Configurator/Configure/Hello1', type: 'POST', dataType: 'json', success: function (data) { console.log(data + "hello1"); } }); } function lala() { $.ajax({ url: '/Configurator/Configure/Hello2', type: 'POST', dataType: 'json', success: function (data) { console.log(data + "hello2"); } });
My C # code, on the other hand, does not do two things at a time:
[HttpPost] public async Task<LoginViewModel> Hello1() { var str = await GetSlowstring(); return str; } [HttpPost] public async Task<LoginViewModel> Hello2() { var str = await GetSlowstring(); return str; } public async Task<LoginViewModel> GetSlowstring() { await Task.Delay(10000); LoginViewModel login = new LoginViewModel(); login.UserName = "HejsN"; return await Task.FromResult(login); }
The combined call should take a little more than 10 seconds if it is made correctly, but now it accepts a double.
Do I need to create a new thread for calls? Or is this done automatically by the application?
EDIT: 
c # asynchronous asp.net-mvc
Daniel Gustafsson
source share