开发者

MVC.net. Sequence of asynch calls of controller methods

开发者 https://www.devze.com 2023-01-17 23:00 出处:网络
I work on MVC.net application. I make asynch requests to my controller via jQuery. Below you can see these requests in fiddler (all of them are fired in a specific sequence).

I work on MVC.net application. I make asynch requests to my controller via jQuery. Below you can see these requests in fiddler (all of them are fired in a specific sequence).

num result protocol Host 开发者_StackOverflow社区 URL

2929 200 HTTP somesite.com:1936 /DynamicTables/SaveCurrentRowsState

2930 200 HTTP somesite.com:1936 /DynamicTables/AddRows?key=30060d39-7531-41a2-8d40-4c53ec34d6ff&rowsCount=5

2930 200 HTTP somesite.com:1936 /DynamicTables/GetNextPage?key=30060d39-7531-41a2-8d40-4c53ec34d6ff&newPageNumber=21&rowsPerPage=30

But server handles these requests in an another sequence (I placed breakpoints on start of each of these methods on the server and so in order to check this sequence). So, actual sequence is: 1) AddRows 2) SaveCurrentRowsState 3) GetNextPage

It seems like asp.net spends different time to handle these requests before it faces my breakpoints. Could somebody help me why it is possible? Is there any way to avoid this situation?

Thanks, Egor


If you are sending a series of async messages to the server, then there is no guarantee in what sequence they will be processed. If you need that level of control, either bundle them all into a single call to the server, or call them synchronously.


The order in which the requests are sent using AJAX from the client is not necessary the order in which they will be received and you should never rely on that. One possible solution would be to send the requests synchronously but this might not be a very good idea because it will freeze the UI while processing them and it kind of defeats the purpose of AJAX.

0

精彩评论

暂无评论...
验证码 换一张
取 消