Two async postbacks at the same time?
I have two timers that each immediately trigger an async postback once the page is rendered. Each of the async postbacks load some expensive data. So, when I debug this, it appears that the first async postback occurs and it's results are displayed then the second async postback occurs only after the first async postback completes.
So, my question is are async postbacks queued by the PageRequestManager or something/whatever? I guess what I am开发者_StackOverflow社区 saying is that I want to perform two async postbacks at the same time and handle the results as they are ready. Is there a way I can make this happen? Could what I am seeing be a result of debugging?
Disclaimer: We do not have many users, but the page needs to load fast. Therefore we don't care how many threads it takes to handle a single page.
Any ideas? Thanks for reading.
You cannot make two async postbacks at the same time because they have to access to:
- to user Session and you cannot to synchronize session modifications between 2 requestst
- to Page ViewState and you cannot return with responses two different unrelated ViewStates, those recreated on every async-request.
You can make few async requests to sessionless HttpHandlers. Correct me if i am wrong :)
So the scenario is as follows:
- Timer T1 fires calling function F1. F1 results in a callback C1 to the server
- Timer T2 fires calling function F2. F2 results in a callback C2 to the server
If T1 and T2 were to fire at "exactly" the same time, then JavaScript can not process F1 and F2 at exactly the same time because JavaScript is a single-threaded environment. One of the events (say F1) would have to complete before the other event (F2) could be fired.
See the following great article by John Resig: How Javascript Timers Work
However, my understanding is that the callbacks C1 & C2 are run asynchronously, so having fired C1 off to the server, F1 can then complete allowing F2 to run and C2 to be fired off to the server.
Then if say C2 returned fractionally before C1, then the results of C2 would have to be fully processed before the results of C1.
So why are you not seeing this behaviour?
I'm not sure, but could it be that your development environment is effectively throttling the number of threads that can be processed sequentially? Were you to run it on a Windows server outside of a debug environment, what would the behaviour be?
精彩评论