locked
Jquery Ajax call with Async WebService - Threading? RRS feed

  • Question

  • User-1637745192 posted

    Hi,

    I am trying to return stats to a dashboard using an Ajax call and C# method in a WebService. Currently this works and each tile is updated with the correct stat but they only get populated after each call is made, one at a time. I need to call the same WebService multiple times (..with different arguments) and somehow thread these so that each tile populates in parallel with the other.

    Currently the dashboard takes about 30seconds to load, which is a lifetime but if I can thread these then I can cut the load time down to 5 seconds.

    I have tried making an async method and various ways of creating Tasks but cant get anything to work. All the examples I have looked at use a .aspx page but I need to do this using a WebSerice page .asmx 

    Hopefully someone can point me in the right direction here or let me know if this is even possible. I can't figure out how the Ajax object knows which response it would be expecting to come out and in which order. 

    Thanks,

    Chris

    Monday, September 9, 2019 4:02 PM

Answers

  • User-474980206 posted
    The server action could make the async database calls at the same time (no additional threads required).

    But the real issue is your database calls are too slow. You should fix them so they are about 200 ms at max. You either have a bad schema, missing indexes or other issue.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 10, 2019 4:31 PM

All replies

  • User753101303 posted

    Hi,

    Client side and server side async is basically unrelated. What do you do currently on the client side ? You are using async:false ?

    Either you have a success callback or a done method that is tailored to each response or you have the same for all requests and your data likely include something to know which "metric" is returned and which tile should be used to show that...

    For now you know which tile to use just based on the ordering ?

    Monday, September 9, 2019 4:17 PM
  • User-1637745192 posted

    Hi Patrice,

    Thanks for your reply. Yes, I am not sure what I am trying to do is possible. I have async: true

    I have a SQL procedure which runs for about 30 seconds and returns all the dashboard statistics in one go, which is too long. Each statistic takes about 5 seconds to calculate, so I thought I could run each one individually at the same time so the user would just wait about 5 seconds for all of the to download.

    I wanted to write a bit of client side script which could call a WebMethod and then the procedure in smaller steps and in parallel, so each tile would display a loading.gif then they all populate at roughly the same time as the data returns. Just to make the user experience smoother.

    I tried using a single code blocks with arguments for all the tiles, which doesn't work. I then I spilt them all up to be into individual Ajax calls, with their own WebService methods which also doesn't work. 

    I think if this theory worked then the web would be a much happier place. But... I am sure I have seen something like this somewhere...

    Thanks, 

    Monday, September 9, 2019 4:33 PM
  • User475983607 posted

    The requests must execute in order due to Session.  Try disabling Session at the page level.

    https://support.microsoft.com/en-us/help/306996/how-to-disable-asp-session-state-in-asp-net

    Monday, September 9, 2019 6:22 PM
  • User-474980206 posted
    The server action could make the async database calls at the same time (no additional threads required).

    But the real issue is your database calls are too slow. You should fix them so they are about 200 ms at max. You either have a bad schema, missing indexes or other issue.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 10, 2019 4:31 PM
  • User-1637745192 posted

    Hi Bruce,

    Thank you for your reply. Yes, I agree our procedure does take too long and I think it is down to some of the design in our databases. Unfortunately  there is nothing I can personally do that about that at the moment, out of my hands. 

    I will figure out how to do the async database calls, and hopefully that will be a good enough work around till the databases are sorted.

    Wednesday, September 25, 2019 7:24 AM